File tree Expand file tree Collapse file tree 3 files changed +11
-15
lines changed Expand file tree Collapse file tree 3 files changed +11
-15
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.
486
+ /// Otherwise this will return self. Panics if min > max.
487
487
///
488
488
/// # Examples
489
489
///
@@ -494,16 +494,18 @@ 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.
500
497
#[ unstable( feature = "clamp" , issue = "44095" ) ]
501
498
fn clamp ( self , min : Self , max : Self ) -> Self
502
499
where Self : Sized {
503
500
assert ! ( min <= max) ;
504
- if self < min { min }
505
- else if self > max { max }
506
- else { self }
501
+ if self < min {
502
+ min
503
+ }
504
+ else if self > max {
505
+ max
506
+ } else {
507
+ self
508
+ }
507
509
}
508
510
}
509
511
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.
1084
+ /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
1085
1085
///
1086
1086
/// # Examples
1087
1087
///
@@ -1093,9 +1093,6 @@ 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.
1099
1096
#[ unstable( feature = "clamp" , issue = "44095" ) ]
1100
1097
#[ inline]
1101
1098
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.
974
+ /// Otherwise this returns self. Panics if min > max, min is NaN, or max is NaN.
975
975
///
976
976
/// # Examples
977
977
///
@@ -983,9 +983,6 @@ 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.
989
986
#[ unstable( feature = "clamp" , issue = "44095" ) ]
990
987
#[ inline]
991
988
pub fn clamp ( self , min : f64 , max : f64 ) -> f64 {
You can’t perform that action at this time.
0 commit comments