Coverage Report

Created: 2025-02-21 07:11

/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/scalbn.rs
Line
Count
Source (jump to first uncovered line)
1
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2
0
pub fn scalbn(x: f64, mut n: i32) -> f64 {
3
0
    let x1p1023 = f64::from_bits(0x7fe0000000000000); // 0x1p1023 === 2 ^ 1023
4
0
    let x1p53 = f64::from_bits(0x4340000000000000); // 0x1p53 === 2 ^ 53
5
0
    let x1p_1022 = f64::from_bits(0x0010000000000000); // 0x1p-1022 === 2 ^ (-1022)
6
0
7
0
    let mut y = x;
8
0
9
0
    if n > 1023 {
10
0
        y *= x1p1023;
11
0
        n -= 1023;
12
0
        if n > 1023 {
13
0
            y *= x1p1023;
14
0
            n -= 1023;
15
0
            if n > 1023 {
16
0
                n = 1023;
17
0
            }
18
0
        }
19
0
    } else if n < -1022 {
20
        /* make sure final n < -53 to avoid double
21
        rounding in the subnormal range */
22
0
        y *= x1p_1022 * x1p53;
23
0
        n += 1022 - 53;
24
0
        if n < -1022 {
25
0
            y *= x1p_1022 * x1p53;
26
0
            n += 1022 - 53;
27
0
            if n < -1022 {
28
0
                n = -1022;
29
0
            }
30
0
        }
31
0
    }
32
0
    y * f64::from_bits(((0x3ff + n) as u64) << 52)
33
0
}