Coverage Report

Created: 2025-07-12 07:16

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