Back to index

glibc  2.9
Functions
s_ilogb.c File Reference
#include <limits.h>
#include "math.h"
#include "math_private.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int __ilogb (double x)

Function Documentation

int __ilogb ( double  x)

Definition at line 31 of file s_ilogb.c.

{
       int32_t hx,lx,ix;

       GET_HIGH_WORD(hx,x);
       hx &= 0x7fffffff;
       if(hx<0x00100000) {
           GET_LOW_WORD(lx,x);
           if((hx|lx)==0)
              return FP_ILOGB0;    /* ilogb(0) = FP_ILOGB0 */
           else                    /* subnormal x */
              if(hx==0) {
                  for (ix = -1043; lx>0; lx<<=1) ix -=1;
              } else {
                  for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
              }
           return ix;
       }
       else if (hx<0x7ff00000) return (hx>>20)-1023;
       else if (FP_ILOGBNAN != INT_MAX) {
           /* ISO C99 requires ilogb(+-Inf) == INT_MAX.  */
           GET_LOW_WORD(lx,x);
           if(((hx^0x7ff00000)|lx) == 0)
              return INT_MAX;
       }
       return FP_ILOGBNAN;
}