ilogb(), ilogbf(), ilogbl()

Compute the integral part of a logarithm

Synopsis:

```#include <math.h>

int ilogb ( double x );

int ilogbf (float x );

int ilogbl ( long double x );
```

Arguments:

x
The number for which you want to compute the integral part of the logarithm.

Library:

libm

Use the -l m option to qcc to link against this library.

Description:

The ilogb() and ilogbf() functions compute the integral part of:

logr |x|

as a signed integral value, for nonzero finite x, where r is the radix of the machine's floating point arithmetic.

To check for error situations, use feclearexcept() and fetestexcept():

• Call feclearexcept(FE_ALL_EXCEPT) before calling ilogb(), ilogbf(), or ilogbl().
• On return, if fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is nonzero, then an error has occurred.

Returns:

The exponent part of x, in integer format:

If x is: These functions return:
0 FP_ILOGB0, and a domain error may occur
NAN FP_ILOGBNAN, and a domain error may occur
±Inf INT_MAX, and a domain error may occur

Examples:

```#include <stdio.h>
#include <math.h>
#include <fenv.h>
#include <stdlib.h>

int main( void )
{
int except_flags;

feclearexcept(FE_ALL_EXCEPT);

printf( "%f\n", ilogb(.5) );

except_flags = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);
if(except_flags) {
/* An error occurred; handle it appropriately. */
}

return EXIT_SUCCESS;
}
```

Classification:

Safety:
Cancellation point No
Interrupt handler No
Signal handler No