From 2e34ff767113c6a15c5862b0646ca9ad7ffd81b1 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Fri, 1 Sep 2017 00:07:26 -0600 Subject: [PATCH] Fix documentation and formatting. --- src/libcore/cmp.rs | 16 +++++++--------- src/libstd/f32.rs | 5 ++++- src/libstd/f64.rs | 5 ++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/libcore/cmp.rs b/src/libcore/cmp.rs index 174ceb6b8a7e6..dc1f2981a50ad 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. Panics if min > max. + /// Otherwise this will return self. /// /// # Examples /// @@ -494,18 +494,16 @@ 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 6b6bd39e7e84c..aaeac06535ee6 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. Panics if min > max, min is NaN, or max is NaN. + /// Otherwise this returns self. /// /// # Examples /// @@ -1093,6 +1093,9 @@ 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 0a7176f9cc75e..4ab319c3cf100 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. Panics if min > max, min is NaN, or max is NaN. + /// Otherwise this returns self. /// /// # Examples /// @@ -983,6 +983,9 @@ 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 {