about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-03-22 19:31:37 +0100
committerGitHub <noreply@github.com>2019-03-22 19:31:37 +0100
commit9943a447c1d0c4151db7eceb20059638fe520f5c (patch)
tree525720d7aefcf5709906fa335e4f024439d334da /src/libstd
parentde08d0ec2da23d7fd878df9ea50150c04fbd8a7b (diff)
parent72f5d9137e33fe4aa251dab44c0fc4de71a1a366 (diff)
downloadrust-9943a447c1d0c4151db7eceb20059638fe520f5c.tar.gz
rust-9943a447c1d0c4151db7eceb20059638fe520f5c.zip
Rollup merge of #59327 - Xaeroxe:clamp-doc, r=scottmcm
Add NAN test to docs

Documents and tests NAN behavior for the new (f32, f64)::clamp function.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/f32.rs19
-rw-r--r--src/libstd/f64.rs19
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs
index 2fabe30fa93..688d9c1aabb 100644
--- a/src/libstd/f32.rs
+++ b/src/libstd/f32.rs
@@ -970,6 +970,7 @@ impl f32 {
     /// assert!((-3.0f32).clamp(-2.0f32, 1.0f32) == -2.0f32);
     /// assert!((0.0f32).clamp(-2.0f32, 1.0f32) == 0.0f32);
     /// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
+    /// assert!((std::f32::NAN).clamp(-2.0f32, 1.0f32).is_nan());
     /// ```
     #[unstable(feature = "clamp", issue = "44095")]
     #[inline]
@@ -1581,4 +1582,22 @@ mod tests {
         assert_eq!(f32::from_bits(masked_nan1).to_bits(), masked_nan1);
         assert_eq!(f32::from_bits(masked_nan2).to_bits(), masked_nan2);
     }
+
+    #[test]
+    #[should_panic]
+    fn test_clamp_min_greater_than_max() {
+        1.0f32.clamp(3.0, 1.0);
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_clamp_min_is_nan() {
+        1.0f32.clamp(NAN, 1.0);
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_clamp_max_is_nan() {
+        1.0f32.clamp(3.0, NAN);
+    }
 }
diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs
index a471117f6d6..b171e1c7ac9 100644
--- a/src/libstd/f64.rs
+++ b/src/libstd/f64.rs
@@ -892,6 +892,7 @@ impl f64 {
     /// assert!((-3.0f64).clamp(-2.0f64, 1.0f64) == -2.0f64);
     /// assert!((0.0f64).clamp(-2.0f64, 1.0f64) == 0.0f64);
     /// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
+    /// assert!((std::f64::NAN).clamp(-2.0f64, 1.0f64).is_nan());
     /// ```
     #[unstable(feature = "clamp", issue = "44095")]
     #[inline]
@@ -1522,4 +1523,22 @@ mod tests {
         assert_eq!(f64::from_bits(masked_nan1).to_bits(), masked_nan1);
         assert_eq!(f64::from_bits(masked_nan2).to_bits(), masked_nan2);
     }
+
+    #[test]
+    #[should_panic]
+    fn test_clamp_min_greater_than_max() {
+        1.0f64.clamp(3.0, 1.0);
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_clamp_min_is_nan() {
+        1.0f64.clamp(NAN, 1.0);
+    }
+
+    #[test]
+    #[should_panic]
+    fn test_clamp_max_is_nan() {
+        1.0f64.clamp(3.0, NAN);
+    }
 }