diff options
| -rw-r--r-- | src/libcore/cmp.rs | 16 | ||||
| -rw-r--r-- | src/libstd/f32.rs | 5 | ||||
| -rw-r--r-- | 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 dc1f2981a50..174ceb6b8a7 100644 --- a/src/libcore/cmp.rs +++ b/src/libcore/cmp.rs @@ -483,7 +483,7 @@ pub trait Ord: Eq + PartialOrd<Self> { } /// 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<Self> { /// 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 aaeac06535e..6b6bd39e7e8 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 4ab319c3cf1..0a7176f9cc7 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 { |
