Coverage Report

Created: 2025-07-12 07:16

/rust/registry/src/index.crates.io-6f17d22bba15001f/libm-0.2.11/src/math/fmod.rs
Line
Count
Source (jump to first uncovered line)
1
use core::u64;
2
3
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
4
0
pub fn fmod(x: f64, y: f64) -> f64 {
5
0
    let mut uxi = x.to_bits();
6
0
    let mut uyi = y.to_bits();
7
0
    let mut ex = (uxi >> 52 & 0x7ff) as i64;
8
0
    let mut ey = (uyi >> 52 & 0x7ff) as i64;
9
0
    let sx = uxi >> 63;
10
0
    let mut i;
11
0
12
0
    if uyi << 1 == 0 || y.is_nan() || ex == 0x7ff {
13
0
        return (x * y) / (x * y);
14
0
    }
15
0
    if uxi << 1 <= uyi << 1 {
16
0
        if uxi << 1 == uyi << 1 {
17
0
            return 0.0 * x;
18
0
        }
19
0
        return x;
20
0
    }
21
0
22
0
    /* normalize x and y */
23
0
    if ex == 0 {
24
0
        i = uxi << 12;
25
0
        while i >> 63 == 0 {
26
0
            ex -= 1;
27
0
            i <<= 1;
28
0
        }
29
0
        uxi <<= -ex + 1;
30
0
    } else {
31
0
        uxi &= u64::MAX >> 12;
32
0
        uxi |= 1 << 52;
33
0
    }
34
0
    if ey == 0 {
35
0
        i = uyi << 12;
36
0
        while i >> 63 == 0 {
37
0
            ey -= 1;
38
0
            i <<= 1;
39
0
        }
40
0
        uyi <<= -ey + 1;
41
0
    } else {
42
0
        uyi &= u64::MAX >> 12;
43
0
        uyi |= 1 << 52;
44
0
    }
45
46
    /* x mod y */
47
0
    while ex > ey {
48
0
        i = uxi.wrapping_sub(uyi);
49
0
        if i >> 63 == 0 {
50
0
            if i == 0 {
51
0
                return 0.0 * x;
52
0
            }
53
0
            uxi = i;
54
0
        }
55
0
        uxi <<= 1;
56
0
        ex -= 1;
57
    }
58
0
    i = uxi.wrapping_sub(uyi);
59
0
    if i >> 63 == 0 {
60
0
        if i == 0 {
61
0
            return 0.0 * x;
62
0
        }
63
0
        uxi = i;
64
0
    }
65
0
    while uxi >> 52 == 0 {
66
0
        uxi <<= 1;
67
0
        ex -= 1;
68
0
    }
69
70
    /* scale result */
71
0
    if ex > 0 {
72
0
        uxi -= 1 << 52;
73
0
        uxi |= (ex as u64) << 52;
74
0
    } else {
75
0
        uxi >>= -ex + 1;
76
0
    }
77
0
    uxi |= (sx as u64) << 63;
78
0
79
0
    f64::from_bits(uxi)
80
0
}