Coverage Report

Created: 2025-06-23 13:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/build/cargo-vendor-dir/libm-0.2.15/src/math/remquof.rs
Line
Count
Source
1
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
2
0
pub fn remquof(mut x: f32, mut y: f32) -> (f32, i32) {
3
0
    let ux: u32 = x.to_bits();
4
0
    let mut uy: u32 = y.to_bits();
5
0
    let mut ex = ((ux >> 23) & 0xff) as i32;
6
0
    let mut ey = ((uy >> 23) & 0xff) as i32;
7
0
    let sx = (ux >> 31) != 0;
8
0
    let sy = (uy >> 31) != 0;
9
0
    let mut q: u32;
10
0
    let mut i: u32;
11
0
    let mut uxi: u32 = ux;
12
0
13
0
    if (uy << 1) == 0 || y.is_nan() || ex == 0xff {
14
0
        return ((x * y) / (x * y), 0);
15
0
    }
16
0
    if (ux << 1) == 0 {
17
0
        return (x, 0);
18
0
    }
19
0
20
0
    /* normalize x and y */
21
0
    if ex == 0 {
22
0
        i = uxi << 9;
23
0
        while (i >> 31) == 0 {
24
0
            ex -= 1;
25
0
            i <<= 1;
26
0
        }
27
0
        uxi <<= -ex + 1;
28
0
    } else {
29
0
        uxi &= (!0) >> 9;
30
0
        uxi |= 1 << 23;
31
0
    }
32
0
    if ey == 0 {
33
0
        i = uy << 9;
34
0
        while (i >> 31) == 0 {
35
0
            ey -= 1;
36
0
            i <<= 1;
37
0
        }
38
0
        uy <<= -ey + 1;
39
0
    } else {
40
0
        uy &= (!0) >> 9;
41
0
        uy |= 1 << 23;
42
0
    }
43
44
0
    q = 0;
45
0
    if ex + 1 != ey {
46
0
        if ex < ey {
47
0
            return (x, 0);
48
0
        }
49
        /* x mod y */
50
0
        while ex > ey {
51
0
            i = uxi.wrapping_sub(uy);
52
0
            if (i >> 31) == 0 {
53
0
                uxi = i;
54
0
                q += 1;
55
0
            }
56
0
            uxi <<= 1;
57
0
            q <<= 1;
58
0
            ex -= 1;
59
        }
60
0
        i = uxi.wrapping_sub(uy);
61
0
        if (i >> 31) == 0 {
62
0
            uxi = i;
63
0
            q += 1;
64
0
        }
65
0
        if uxi == 0 {
66
0
            ex = -30;
67
0
        } else {
68
0
            while (uxi >> 23) == 0 {
69
0
                uxi <<= 1;
70
0
                ex -= 1;
71
0
            }
72
        }
73
0
    }
74
75
    /* scale result and decide between |x| and |x|-|y| */
76
0
    if ex > 0 {
77
0
        uxi -= 1 << 23;
78
0
        uxi |= (ex as u32) << 23;
79
0
    } else {
80
0
        uxi >>= -ex + 1;
81
0
    }
82
0
    x = f32::from_bits(uxi);
83
0
    if sy {
84
0
        y = -y;
85
0
    }
86
0
    if ex == ey || (ex + 1 == ey && (2.0 * x > y || (2.0 * x == y && (q % 2) != 0))) {
87
0
        x -= y;
88
0
        q += 1;
89
0
    }
90
0
    q &= 0x7fffffff;
91
0
    let quo = if sx ^ sy { -(q as i32) } else { q as i32 };
92
0
    if sx { (-x, quo) } else { (x, quo) }
93
0
}