Rate This Document
Findability
Accuracy
Completeness
Readability

ilogb

Compute the exponent of x and returns 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.

Dependencies

C: "km.h"

Examples

C interface:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    // typical usage
    double x1 = 0.0, x2 = -0.0, x3 = 0x1p-1074, x4 = 0x1p1024;
    float x5 = 0x1p-149f;
    // special handling
    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-149) = %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) = INT_MIN
     * ilogb(-0.0) = INT_MIN
     * ilogb(0x1p-1074) = -1074
     * ilogb(0x1p1024) = INT_MAX
     * ilogbf(0x1p-149) = -149
     * ilogb(INFINITY) = INT_MAX
     * ilogb(-INFINITY) = INT_MAX
     * ilogb(NAN) = INT_MAX
     *
     * */