Coverage Report

Created: 2024-09-10 12:50

/build/cargo-vendor-dir/libm-0.2.8/src/math/roundf.rs
Line
Count
Source
1
use super::copysignf;
2
use super::truncf;
3
use core::f32;
4
5
#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
6
4
pub fn roundf(x: f32) -> f32 {
7
4
    truncf(x + copysignf(0.5 - 0.25 * f32::EPSILON, x))
8
4
}
9
10
// PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
11
#[cfg(not(target_arch = "powerpc64"))]
12
#[cfg(test)]
13
mod tests {
14
    use super::roundf;
15
16
    #[test]
17
    fn negative_zero() {
18
        assert_eq!(roundf(-0.0_f32).to_bits(), (-0.0_f32).to_bits());
19
    }
20
21
    #[test]
22
    fn sanity_check() {
23
        assert_eq!(roundf(-1.0), -1.0);
24
        assert_eq!(roundf(2.8), 3.0);
25
        assert_eq!(roundf(-0.5), -1.0);
26
        assert_eq!(roundf(0.5), 1.0);
27
        assert_eq!(roundf(-1.5), -2.0);
28
        assert_eq!(roundf(1.5), 2.0);
29
    }
30
}