libm/math/
ilogbf.rs

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 ilogbf(x: f32) -> i32 {
6    let mut i = x.to_bits();
7    let e = ((i >> 23) & 0xff) as i32;
8
9    if e == 0 {
10        i <<= 9;
11        if i == 0 {
12            force_eval!(0.0 / 0.0);
13            return FP_ILOGB0;
14        }
15        /* subnormal x */
16        let mut e = -0x7f;
17        while (i >> 31) == 0 {
18            e -= 1;
19            i <<= 1;
20        }
21        e
22    } else if e == 0xff {
23        force_eval!(0.0 / 0.0);
24        if (i << 9) != 0 { FP_ILOGBNAN } else { i32::max_value() }
25    } else {
26        e - 0x7f
27    }
28}