1const FP_ILOGBNAN: i32 = -1 - 0x7fffffff;
2const FP_ILOGB0: i32 = FP_ILOGBNAN;
3
4#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
5pub fn ilogb(x: f64) -> i32 {
6 let mut i: u64 = x.to_bits();
7 let e = ((i >> 52) & 0x7ff) as i32;
8
9 if e == 0 {
10 i <<= 12;
11 if i == 0 {
12 force_eval!(0.0 / 0.0);
13 return FP_ILOGB0;
14 }
15 /* subnormal x */
16 let mut e = -0x3ff;
17 while (i >> 63) == 0 {
18 e -= 1;
19 i <<= 1;
20 }
21 e
22 } else if e == 0x7ff {
23 force_eval!(0.0 / 0.0);
24 if (i << 12) != 0 {
25 FP_ILOGBNAN
26 } else {
27 i32::max_value()
28 }
29 } else {
30 e - 0x3ff
31 }
32}
33