TODO update
[libm] / src / math / ilogbf.c
1 #include <limits.h>
2 #include "libm.h"
3
4 int ilogbf(float x)
5 {
6         union fshape u = {x};
7         int e = u.bits>>23 & 0xff;
8
9         if (!e) {
10                 u.bits <<= 9;
11                 if (u.bits == 0)
12                         return FP_ILOGB0;
13                 /* subnormal x */
14                 for (e = -0x7f; u.bits < (uint32_t)1<<31; e--, u.bits<<=1);
15                 return e;
16         }
17         if (e == 0xff)
18                 return u.bits<<9 ? FP_ILOGBNAN : INT_MAX;
19         return e - 0x7f;
20 }