File tree 3 files changed +15
-11
lines changed
3 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -483,7 +483,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
483
483
}
484
484
485
485
/// Returns max if self is greater than max, and min if self is less than min.
486
- /// Otherwise this will return self. Panics if min > max.
486
+ /// Otherwise this will return self.
487
487
///
488
488
/// # Examples
489
489
///
@@ -494,18 +494,16 @@ pub trait Ord: Eq + PartialOrd<Self> {
494
494
/// assert!(0.clamp(-2, 1) == 0);
495
495
/// assert!(2.clamp(-2, 1) == 1);
496
496
/// ```
497
+ ///
498
+ /// # Panics
499
+ /// Panics if min > max.
497
500
#[ unstable( feature = "clamp" , issue = "44095" ) ]
498
501
fn clamp ( self , min : Self , max : Self ) -> Self
499
502
where Self : Sized {
500
503
assert ! ( min <= max) ;
501
- if self < min {
502
- min
503
- }
504
- else if self > max {
505
- max
506
- } else {
507
- self
508
- }
504
+ if self < min { min }
505
+ else if self > max { max }
506
+ else { self }
509
507
}
510
508
}
511
509
Original file line number Diff line number Diff line change @@ -1081,7 +1081,7 @@ impl f32 {
1081
1081
}
1082
1082
1083
1083
/// Returns max if self is greater than max, and min if self is less than min.
1084
- /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
1084
+ /// Otherwise this returns self.
1085
1085
///
1086
1086
/// # Examples
1087
1087
///
@@ -1093,6 +1093,9 @@ impl f32 {
1093
1093
/// assert!((2.0f32).clamp(-2.0f32, 1.0f32) == 1.0f32);
1094
1094
/// assert!((NAN).clamp(-2.0f32, 1.0f32).is_nan());
1095
1095
/// ```
1096
+ ///
1097
+ /// # Panics
1098
+ /// Panics if min > max, min is NaN, or max is NaN.
1096
1099
#[ unstable( feature = "clamp" , issue = "44095" ) ]
1097
1100
#[ inline]
1098
1101
pub fn clamp ( self , min : f32 , max : f32 ) -> f32 {
Original file line number Diff line number Diff line change @@ -971,7 +971,7 @@ impl f64 {
971
971
}
972
972
973
973
/// Returns max if self is greater than max, and min if self is less than min.
974
- /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
974
+ /// Otherwise this returns self.
975
975
///
976
976
/// # Examples
977
977
///
@@ -983,6 +983,9 @@ impl f64 {
983
983
/// assert!((2.0f64).clamp(-2.0f64, 1.0f64) == 1.0f64);
984
984
/// assert!((NAN).clamp(-2.0f64, 1.0f64).is_nan());
985
985
/// ```
986
+ ///
987
+ /// # Panics
988
+ /// Panics if min > max, min is NaN, or max is NaN.
986
989
#[ unstable( feature = "clamp" , issue = "44095" ) ]
987
990
#[ inline]
988
991
pub fn clamp ( self , min : f64 , max : f64 ) -> f64 {
You can’t perform that action at this time.
0 commit comments