From c7f54daaf44b16469193b03694360153c82aab08 Mon Sep 17 00:00:00 2001 From: Jacob Kiesel Date: Sat, 17 Sep 2022 18:09:50 -0600 Subject: [PATCH] Add better assert messages for f32/f64 clamps --- library/core/src/num/f32.rs | 2 +- library/core/src/num/f64.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 2c6a0ba64f266..d946f6547b0d7 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -1391,7 +1391,7 @@ impl f32 { #[stable(feature = "clamp", since = "1.50.0")] #[inline] pub fn clamp(mut self, min: f32, max: f32) -> f32 { - assert!(min <= max); + assert!(min <= max, "min > max, or either was NaN. min = {min:?}, max = {max:?}"); if self < min { self = min; } diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index fd3c18ce29bd2..b96af86aabaf1 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -1389,7 +1389,7 @@ impl f64 { #[stable(feature = "clamp", since = "1.50.0")] #[inline] pub fn clamp(mut self, min: f64, max: f64) -> f64 { - assert!(min <= max); + assert!(min <= max, "min > max, or either was NaN. min = {min:?}, max = {max:?}"); if self < min { self = min; }