1#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2pub fn scalbnf(mut x: f32, mut n: i32) -> f32 {
3 let x1p127 = f32::from_bits(0x7f000000); // 0x1p127f === 2 ^ 127
4 let x1p_126 = f32::from_bits(0x800000); // 0x1p-126f === 2 ^ -126
5 let x1p24 = f32::from_bits(0x4b800000); // 0x1p24f === 2 ^ 24
6
7 if n > 127 {
8 x *= x1p127;
9 n -= 127;
10 if n > 127 {
11 x *= x1p127;
12 n -= 127;
13 if n > 127 {
14 n = 127;
15 }
16 }
17 } else if n < -126 {
18 x *= x1p_126 * x1p24;
19 n += 126 - 24;
20 if n < -126 {
21 x *= x1p_126 * x1p24;
22 n += 126 - 24;
23 if n < -126 {
24 n = -126;
25 }
26 }
27 }
28 x * f32::from_bits(((0x7f + n) as u32) << 23)
29}
30