Rate This Document
Findability
Accuracy
Completeness
Readability

ilogb

Compute the exponent of x and return the value as an integer.

Interface Definition

C interface:

int ilogbf(float x);

int ilogb(double x);

int ilogbl(long double x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For ilogbf, x is of single-precision floating-point type.
  • For ilogb, x is of double-precision floating-point type.
  • For ilogbl, x is of long double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

  • If input x is ±∞, the return value is INT_MAX.
  • If the input x is ±0, the return value is INT_MIN.
  • If input x is NaN, the return value is INT_MAX.

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 0x1p-1074, x4 = 0x1p1024;
    float x5 = 0x1p-149f;
    // special handing
    double a = INFINITY, b = -INFINITY, c = NAN;
    // print result
    printf("ilogb(0.0) = %d\n", ilogb(x1));
    printf("ilogb(-0.0) = %d\n", ilogb(x2));
    printf("ilogb(0x1p-1074) = %d\n", ilogb(x3));
    printf("ilogb(0x1p1024) = %d\n", ilogb(x4));
    printf("ilogbf(0x1p-150) = %d\n", ilogbf(x5));
    printf("ilogb(INFINITY) = %d\n", ilogb(a));
    printf("ilogb(-INFINITY) = %d\n", ilogb(b));
    printf("ilogb(NAN) = %d\n", ilogb(c));
    /*
     * ilogb(0.0) = -inf
     * ilogb(-0.0) = -inf
     * ilogb(0x1p-1074) = -1074.000000000000000
     * ilogb(0x1p1024) = inf
     * ilogbf(0x1p-150) = -149.000000000000000
     * ilogb(INFINITY) = inf
     * ilogb(-INFINITY) = inf
     * ilogb(NAN) = nan
     *
     * */