@@ -1325,17 +1325,20 @@ impl f128 {
13251325 self . clamp ( -limit, limit)
13261326 }
13271327
1328- /// Restrict a value to a certain range.
1328+ /// Restrict a value to a certain range, unless it is NaN .
13291329 ///
13301330 /// This is largely equal to `max`, `min`, or `clamp`, depending on whether the range is
1331- /// `min..`, `..=max`, or `min..=max`, respectively. However, whereas `clamp` panics on NaN
1332- /// values, this function treats them as unbounded, like `max` and `min`.
1331+ /// `min..`, `..=max`, or `min..=max`, respectively. However, unlike `max` and `min`, it will
1332+ /// panic if any bound is NaN.
1333+ ///
1334+ /// Note that this function returns NaN if the initial value was NaN as
1335+ /// well.
13331336 ///
13341337 /// Exclusive ranges are not permitted.
13351338 ///
13361339 /// # Panics
13371340 ///
1338- /// Panics on `min..=max` if `min > max`.
1341+ /// Panics on `min..=max` if `min > max`, or if any bound is NaN .
13391342 ///
13401343 /// # Examples
13411344 ///
@@ -1345,7 +1348,7 @@ impl f128 {
13451348 /// assert_eq!(0.0f128.clamp_to(-2.0..=1.0), 0.0);
13461349 /// assert_eq!(2.0f128.clamp_to(..=1.0), 1.0);
13471350 /// assert_eq!(5.0f128.clamp_to(7.0..), 7.0);
1348- /// assert_eq!(4.0f128. clamp_to(1.0..=f128::NAN), 4.0 );
1351+ /// assert!(f128::NAN. clamp_to(1.0..=2.0).is_nan() );
13491352 /// ```
13501353 #[ must_use]
13511354 #[ inline]
0 commit comments