fix struct layout mismatch in sound ioctl time32 fallback conversion
[musl.git] / src / math / ilogb.c
blob64d40154d60ab065b8597d69faef4f76a2fac49d
1 #include <limits.h>
2 #include "libm.h"
4 int ilogb(double x)
6 #pragma STDC FENV_ACCESS ON
7 union {double f; uint64_t i;} u = {x};
8 uint64_t i = u.i;
9 int e = i>>52 & 0x7ff;
11 if (!e) {
12 i <<= 12;
13 if (i == 0) {
14 FORCE_EVAL(0/0.0f);
15 return FP_ILOGB0;
17 /* subnormal x */
18 for (e = -0x3ff; i>>63 == 0; e--, i<<=1);
19 return e;
21 if (e == 0x7ff) {
22 FORCE_EVAL(0/0.0f);
23 return i<<12 ? FP_ILOGBNAN : INT_MAX;
25 return e - 0x3ff;