ilogb(), ilogbf(), ilogbl() — Integer unbiased exponent

Standards

Standards / Extensions C or C++ Dependencies
XPG4.2
C99
Single UNIX Specification, Version 3
C++ TR1 C99
both
z/OS® V1R7

Format

#define _XOPEN_SOURCE_EXTENDED 1
#include <math.h>

int ilogb(double x);
C99:
#define _ISOC99_SOURCE
#include <math.h>

int ilogbf(float x);
int ilogbl(long double x);
C++ TR1 C99:
#define _TR1_C99
#include <math.h>

int ilogb(float x); 
int ilogb(long double x);

General description

The ilogb() functions returns the unbiased exponent of its argument x as an integer.
Note: The following table shows the viable formats for these functions. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Function Hex IEEE
ilogb X X
ilogbf X X
ilogbl X X

Returned value

If successful, the ilogb() functions return the unbiased exponent of x as an integer.

If x is 0, the value FP_ILOGB0 is returned.

if x is a NaN, ilogb() will return FP_ILOGBNAN

if x is infinity, ilogb() will return INT_MAX

If the correct value is greater than {INT_MAX}, {INT_MAX} is returned and a domain error occurs.

If the correct value is less than {INT_MIN}, {INT_MIN} is returned and a domain error occurs.

Special behavior for hex: This function will return the unbiased exponent minus 1 (Because hex representation has no hidden bit, this treatment is needed to satisfy the logb() inequality).
Error Code
Description
EDOM
The x argument is zero, NaN, or ±inf, or the correct value is not representable as an integer.

Related information