Coverage Report

Created: 2024-11-19 11:03

/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
29
pub fn roundf(x: f32) -> f32 {
7
29
    truncf(x + copysignf(0.5 - 0.25 * f32::EPSILON, x))
8
29
}
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
}