@@ -960,17 +960,27 @@ impl f32 {
960
960
pub fn atanh ( self ) -> f32 {
961
961
0.5 * ( ( 2.0 * self ) / ( 1.0 - self ) ) . ln_1p ( )
962
962
}
963
- /// Returns max if self is greater than max, and min if self is less than min.
964
- /// Otherwise this returns self. Panics if min > max, min equals NaN, or max equals NaN.
963
+
964
+ /// Restrict a value to a certain interval unless it is NaN.
965
+ ///
966
+ /// Returns `max` if `self` is greater than `max`, and `min` if `self` is
967
+ /// less than `min`. Otherwise this returns `self`.
968
+ ///
969
+ /// Not that this function returns NaN if the initial value was NaN as
970
+ /// well.
971
+ ///
972
+ /// # Panics
973
+ ///
974
+ /// Panics if `min > max`, `min` is NaN, or `max` is NaN.
965
975
///
966
976
/// # Examples
967
977
///
968
978
/// ```
969
979
/// #![feature(clamp)]
970
- /// assert!((-3.0f32).clamp(-2.0f32 , 1.0f32 ) == -2.0f32 );
971
- /// assert!((0.0f32).clamp(-2.0f32 , 1.0f32 ) == 0.0f32 );
972
- /// assert!((2.0f32).clamp(-2.0f32 , 1.0f32 ) == 1.0f32 );
973
- /// assert!((std::f32::NAN).clamp(-2.0f32 , 1.0f32 ).is_nan());
980
+ /// assert!((-3.0f32).clamp(-2.0 , 1.0 ) == -2.0 );
981
+ /// assert!((0.0f32).clamp(-2.0 , 1.0 ) == 0.0 );
982
+ /// assert!((2.0f32).clamp(-2.0 , 1.0 ) == 1.0 );
983
+ /// assert!((std::f32::NAN).clamp(-2.0 , 1.0 ).is_nan());
974
984
/// ```
975
985
#[ unstable( feature = "clamp" , issue = "44095" ) ]
976
986
#[ inline]
0 commit comments