diff options
Diffstat (limited to 'vendor/compiler_builtins/libm/src/math/roundf.rs')
-rw-r--r-- | vendor/compiler_builtins/libm/src/math/roundf.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/vendor/compiler_builtins/libm/src/math/roundf.rs b/vendor/compiler_builtins/libm/src/math/roundf.rs new file mode 100644 index 000000000..becdb5620 --- /dev/null +++ b/vendor/compiler_builtins/libm/src/math/roundf.rs @@ -0,0 +1,30 @@ +use super::copysignf; +use super::truncf; +use core::f32; + +#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)] +pub fn roundf(x: f32) -> f32 { + truncf(x + copysignf(0.5 - 0.25 * f32::EPSILON, x)) +} + +// PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520 +#[cfg(not(target_arch = "powerpc64"))] +#[cfg(test)] +mod tests { + use super::roundf; + + #[test] + fn negative_zero() { + assert_eq!(roundf(-0.0_f32).to_bits(), (-0.0_f32).to_bits()); + } + + #[test] + fn sanity_check() { + assert_eq!(roundf(-1.0), -1.0); + assert_eq!(roundf(2.8), 3.0); + assert_eq!(roundf(-0.5), -1.0); + assert_eq!(roundf(0.5), 1.0); + assert_eq!(roundf(-1.5), -2.0); + assert_eq!(roundf(1.5), 2.0); + } +} |