]> git.proxmox.com Git - rustc.git/blobdiff - vendor/compiler_builtins/libm/src/math/floorf.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / vendor / compiler_builtins / libm / src / math / floorf.rs
index ae605e1918f68e8ba8de09d410dc813dc2feb0f4..287f08642778dfb31f4e9e6b0aafaa313aba37b7 100644 (file)
@@ -1,9 +1,8 @@
 use core::f32;
 
-/// Floor (f64)
+/// Floor (f32)
 ///
 /// Finds the nearest integer less than or equal to `x`.
-#[inline]
 #[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
 pub fn floorf(x: f32) -> f32 {
     // On wasm32 we know that LLVM's intrinsic will compile to an optimized
@@ -43,8 +42,23 @@ pub fn floorf(x: f32) -> f32 {
 
 #[cfg(test)]
 mod tests {
+    use super::*;
+    use core::f32::*;
+
     #[test]
-    fn no_overflow() {
-        assert_eq!(super::floorf(0.5), 0.0);
+    fn sanity_check() {
+        assert_eq!(floorf(0.5), 0.0);
+        assert_eq!(floorf(1.1), 1.0);
+        assert_eq!(floorf(2.9), 2.0);
+    }
+
+    /// The spec: https://en.cppreference.com/w/cpp/numeric/math/floor
+    #[test]
+    fn spec_tests() {
+        // Not Asserted: that the current rounding mode has no effect.
+        assert!(floorf(NAN).is_nan());
+        for f in [0.0, -0.0, INFINITY, NEG_INFINITY].iter().copied() {
+            assert_eq!(floorf(f), f);
+        }
     }
 }