Skip to content

Commit 3e565f1

Browse files
committed
Auto merge of rust-lang#101959 - Xaeroxe:clamp-better-assert, r=ChrisDenton
Add better assert messages for f32/f64 clamps
2 parents 71ef9ec + c7f54da commit 3e565f1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

library/core/src/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ impl f32 {
13911391
#[stable(feature = "clamp", since = "1.50.0")]
13921392
#[inline]
13931393
pub fn clamp(mut self, min: f32, max: f32) -> f32 {
1394-
assert!(min <= max);
1394+
assert!(min <= max, "min > max, or either was NaN. min = {min:?}, max = {max:?}");
13951395
if self < min {
13961396
self = min;
13971397
}

library/core/src/num/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ impl f64 {
13891389
#[stable(feature = "clamp", since = "1.50.0")]
13901390
#[inline]
13911391
pub fn clamp(mut self, min: f64, max: f64) -> f64 {
1392-
assert!(min <= max);
1392+
assert!(min <= max, "min > max, or either was NaN. min = {min:?}, max = {max:?}");
13931393
if self < min {
13941394
self = min;
13951395
}

0 commit comments

Comments
 (0)