Facebook Page Twitter Page LinkedIn Page
× C Standard Library

The C <math.h> ilogb() function returns the integer part of the logarithm of |x| (mod of argument), using FLT_RADIX as base for the logarithm. On most platforms, FLT_RADIX is 2.

In special cases, macros - FP_ILOGB0 and FP_ILOGBNAN are returned by this function:

FP_ILOGB0 Returned when x is zero.
FP_ILOGBNAN Returned when x is NaN.


Lets consider below example to understand macros - FP_ILOGB0 and FP_ILOGBNAN.

#include <stdio.h>
#include <math.h>
int main (){
  //returned value when argument is zero
  printf("ilogb(0) = %d\n", ilogb(0));
  printf("FP_ILOGB0 = %d\n", FP_ILOGB0);

  //returned value when argument is NaN
  printf("ilogb(sqrt(-1)) = %d\n", ilogb(sqrt(-1)));
  printf("FP_ILOGBNAN = %d\n", FP_ILOGBNAN);
  return 0;

The output of the above code will be:

ilogb(0) = -2147483648
FP_ILOGB0 = -2147483648

ilogb(sqrt(-1)) = -2147483648
FP_ILOGBNAN = -2147483648

❮ C <math.h> Library