From 67283fa8e6ec6ffb1db782c6862d3bdec45cecf8 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 8 Sep 2017 16:07:09 -0600 Subject: [PATCH 1/6] Revert "Add panic unit tests" This reverts commit b762283e57ff71f6763effb9cfc7fc0c7967b6b0. --- src/libstd/f32.rs | 18 ------------------ src/libstd/f64.rs | 18 ------------------ src/libstd/lib.rs | 1 - 3 files changed, 37 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 69ca77f54b44a..aaeac06535ee6 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1777,22 +1777,4 @@ mod tests { assert_ne!(nan_masked & QNAN_MASK, 0); assert!(nan_masked_fl.is_nan()); } - - #[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 6ec633bfaaac1..4ab319c3cf100 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -1668,22 +1668,4 @@ mod tests { assert_approx_eq!(f64::from_bits(0x4094e40000000000), 1337.0); assert_approx_eq!(f64::from_bits(0xc02c800000000000), -14.25); } - - #[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); - } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 191f7fe648ed2..cf1eb5cd52ea4 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -249,7 +249,6 @@ #![feature(cfg_target_vendor)] #![feature(char_error_internals)] #![feature(char_internals)] -#![feature(clamp)] #![feature(collections_range)] #![feature(compiler_builtins_lib)] #![feature(const_fn)] From 8b9616700421a497c107b35a8f5746fb27a44462 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 8 Sep 2017 16:07:13 -0600 Subject: [PATCH 2/6] Revert "Fix documentation and formatting." This reverts commit 2e34ff767113c6a15c5862b0646ca9ad7ffd81b1. --- src/libcore/cmp.rs | 16 +++++++++------- src/libstd/f32.rs | 5 +---- src/libstd/f64.rs | 5 +---- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index dc1f2981a50ad..174ceb6b8a7e6 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -483,7 +483,7 @@ pub trait Ord: Eq + PartialOrd { } /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this will return self. + /// Otherwise this will return self. Panics if min > max. /// /// # Examples /// @@ -494,16 +494,18 @@ pub trait Ord: Eq + PartialOrd { /// assert!(0.clamp(-2, 1) == 0); /// assert!(2.clamp(-2, 1) == 1); /// ``` - /// - /// # Panics - /// Panics if min > max. #[unstable(feature = "clamp", issue = "44095")] fn clamp(self, min: Self, max: Self) -> Self where Self: Sized { assert!(min <= max); - if self < min { min } - else if self > max { max } - else { self } + if self < min { + min + } + else if self > max { + max + } else { + self + } } } diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index aaeac06535ee6..6b6bd39e7e84c 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1081,7 +1081,7 @@ impl f32 { } /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this returns self. + /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN. /// /// # Examples /// @@ -1093,9 +1093,6 @@ impl f32 { /// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32); /// assert!((NAN).clamp(-2.0f32, 1.0f32).is_nan()); /// ``` - /// - /// # Panics - /// Panics if min > max, min is NaN, or max is NaN. #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f32, max: f32) -> f32 { diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 4ab319c3cf100..0a7176f9cc75e 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -971,7 +971,7 @@ impl f64 { } /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this returns self. + /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN. /// /// # Examples /// @@ -983,9 +983,6 @@ impl f64 { /// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64); /// assert!((NAN).clamp(-2.0f64, 1.0f64).is_nan()); /// ``` - /// - /// # Panics - /// Panics if min > max, min is NaN, or max is NaN. #[unstable(feature = "clamp", issue = "44095")] #[inline] pub fn clamp(self, min: f64, max: f64) -> f64 { From 15d3eeaf65692e5ad2313c605906eb65f6c8fe3c Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 8 Sep 2017 16:07:15 -0600 Subject: [PATCH 3/6] Revert "Fix f64 examples" This reverts commit 576426a05a1a6cb33eece7082d7341b7c6bb5277. --- src/libstd/f64.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index 0a7176f9cc75e..ab8f2cd2fdfbd 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -971,17 +971,15 @@ impl f64 { } /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN. + /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN. /// /// # Examples /// /// ``` - /// #![feature(clamp)] - /// use std::f64::NAN; /// 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!((NAN).clamp(-2.0f64, 1.0f64).is_nan()); + /// assert!((NAN).clamp(-2.0f64, 1.0f64) == NAN); /// ``` #[unstable(feature = "clamp", issue = "44095")] #[inline] From eafdad511ff46e82b3e4c1c60b6fa843a33ee0f4 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 8 Sep 2017 16:07:17 -0600 Subject: [PATCH 4/6] Revert "Fix f32 examples." This reverts commit 61f20f8df02e53ee60dc1719ce0e502eecebf8b4. --- src/libstd/f32.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 6b6bd39e7e84c..cef53671e806c 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1081,17 +1081,15 @@ impl f32 { } /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN. + /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN. /// /// # Examples /// /// ``` - /// #![feature(clamp)] - /// use std::f32::NAN; /// 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!((NAN).clamp(-2.0f32, 1.0f32).is_nan()); + /// assert!((NAN).clamp(-2.0f32, 1.0f32) == NAN); /// ``` #[unstable(feature = "clamp", issue = "44095")] #[inline] From 63f4dab0f5049bda995d043ac6c1bdd05a9865e6 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 8 Sep 2017 16:07:19 -0600 Subject: [PATCH 5/6] Revert "Add NAN examples" This reverts commit f74c5d2e18e50c24de2cc1192bf2088cdaa61916. --- src/libstd/f32.rs | 1 - src/libstd/f64.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index cef53671e806c..18bc27faa8227 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1089,7 +1089,6 @@ 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!((NAN).clamp(-2.0f32, 1.0f32) == NAN); /// ``` #[unstable(feature = "clamp", issue = "44095")] #[inline] diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index ab8f2cd2fdfbd..b04ba9eabdbb3 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -979,7 +979,6 @@ 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!((NAN).clamp(-2.0f64, 1.0f64) == NAN); /// ``` #[unstable(feature = "clamp", issue = "44095")] #[inline] From db5b5f97063bd12cb5fb857e33cc5b417b408ef8 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 8 Sep 2017 16:07:21 -0600 Subject: [PATCH 6/6] Revert "Add clamp functions" This reverts commit c589f867f89d4e6e48c6602aed8e878208d4822f. --- src/libcore/cmp.rs | 26 -------------------------- src/libstd/f32.rs | 20 -------------------- src/libstd/f64.rs | 20 -------------------- 3 files changed, 66 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 174ceb6b8a7e6..ec6525485f7a1 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -481,32 +481,6 @@ pub trait Ord: Eq + PartialOrd { where Self: Sized { if self <= other { self } else { other } } - - /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this will return self. Panics if min > max. - /// - /// # Examples - /// - /// ``` - /// #![feature(clamp)] - /// - /// assert!((-3).clamp(-2, 1) == -2); - /// assert!(0.clamp(-2, 1) == 0); - /// assert!(2.clamp(-2, 1) == 1); - /// ``` - #[unstable(feature = "clamp", issue = "44095")] - fn clamp(self, min: Self, max: Self) -> Self - where Self: Sized { - assert!(min <= max); - if self < min { - min - } - else if self > max { - max - } else { - self - } - } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 18bc27faa8227..0135cd0a588cf 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -1080,26 +1080,6 @@ impl f32 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() } - /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN. - /// - /// # Examples - /// - /// ``` - /// 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); - /// ``` - #[unstable(feature = "clamp", issue = "44095")] - #[inline] - pub fn clamp(self, min: f32, max: f32) -> f32 { - assert!(min <= max); - let mut x = self; - if x < min { x = min; } - if x > max { x = max; } - x - } - /// Raw transmutation to `u32`. /// /// Converts the `f32` into its raw memory representation, diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index b04ba9eabdbb3..d73d7cd2c7bd1 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -970,26 +970,6 @@ impl f64 { 0.5 * ((2.0 * self) / (1.0 - self)).ln_1p() } - /// Returns max if self is greater than max, and min if self is less than min. - /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN. - /// - /// # Examples - /// - /// ``` - /// 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); - /// ``` - #[unstable(feature = "clamp", issue = "44095")] - #[inline] - pub fn clamp(self, min: f64, max: f64) -> f64 { - assert!(min <= max); - let mut x = self; - if x < min { x = min; } - if x > max { x = max; } - x - } - // Solaris/Illumos requires a wrapper around log, log2, and log10 functions // because of their non-standard behavior (e.g. log(-n) returns -Inf instead // of expected NaN).