ilogb - C math.h

C examples for math.h:ilogb

Type

function

From

<cmath>
<ctgmath>
<math.h>

Description

Returns the integral part of the logarithm of |x|, using FLT_RADIX as base for the logarithm.

Two specific macro constants may be returned by this function to indicate the following special cases:

macro description
FP_ILOGB0 x is zero
FP_ILOGBNAN x is NaN

Prototype

int ilogb  (double x);
int ilogbf (float x);
int ilogbl (long double x);
int ilogb (float x);
int ilogb (long double x);
int ilogb (T x);           

Parameters

Parameter Description
x Value whose ilogb is returned.

Return Value

  • If x is normal, the base FLT_RADIX logarithm of x.
  • If x is subnormal, the value returned is the one corresponding to the normalized representation (negative exponent).
  • If x is zero, it returns FP_LOGB0.
  • If x is infinite, it returns INT_MAX.
  • If x is NaN, it returns FP_ILOGBNAN.

Example

Demo Code


#include <stdio.h>
#include <math.h> /* ilogb */

int main ()/*from  w w w  .ja  v  a2  s  . c  o  m*/
{
  double param = 10.0;
  
  int result = ilogb (param);
  
  printf ("ilogb(%f) = %d\n", param, result);
  
  return 0;
}

Related Tutorials