C++ Standard Library C++ STL Library

C++ <cmath> - FP_ILOGB0, FP_ILOGBNAN



The C++ <cmath> 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:

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

Example:

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

#include <iostream>
#include <cmath>

using namespace std;
 
int main (){
  //returned value when argument is zero
  cout<<"ilogb(0) = "<<ilogb(0)<<"\n";
  cout<<"FP_ILOGB0 = "<<FP_ILOGB0<<"\n";

  cout<<endl;
  
  //returned value when argument is NaN
  cout<<"ilogb(sqrt(-1)) = "<<ilogb(sqrt(-1))<<"\n";
  cout<<"FP_ILOGBNAN = "<<FP_ILOGBNAN<<"\n";
  return 0;
}

The output of the above code will be:

ilogb(0) = -2147483648
FP_ILOGB0 = -2147483648

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

❮ C++ <cmath> Library