about summary refs log tree commit diff
path: root/library/compiler-builtins/libm/src/math/floor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/compiler-builtins/libm/src/math/floor.rs')
-rw-r--r--library/compiler-builtins/libm/src/math/floor.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/library/compiler-builtins/libm/src/math/floor.rs b/library/compiler-builtins/libm/src/math/floor.rs
index 91825e3c88f..b2b760570de 100644
--- a/library/compiler-builtins/libm/src/math/floor.rs
+++ b/library/compiler-builtins/libm/src/math/floor.rs
@@ -38,3 +38,25 @@ pub fn floor(x: f64) -> f64 {
         x + y
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use core::f64::*;
+
+    #[test]
+    fn sanity_check() {
+        assert_eq!(floor(1.1), 1.0);
+        assert_eq!(floor(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!(floor(NAN).is_nan());
+        for f in [0.0, -0.0, INFINITY, NEG_INFINITY].iter().copied() {
+            assert_eq!(floor(f), f);
+        }
+    }
+}