From 028c78c6c70eb4e9aaf67df1fe650c07209f32ea Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 19 Sep 2023 10:06:22 +0200 Subject: [PATCH] explain mysterious addition in float minimum/maximum --- library/core/src/num/f32.rs | 1 + library/core/src/num/f64.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 3144db197074b..290f649f9acd6 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -957,6 +957,7 @@ impl f32 { } else if self == other { if self.is_sign_negative() && other.is_sign_positive() { self } else { other } } else { + // At least one input is NaN. Use `+` to perform NaN propagation and quieting. self + other } } diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index 20833defc41b8..7569d2cd6ca97 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -968,6 +968,7 @@ impl f64 { } else if self == other { if self.is_sign_negative() && other.is_sign_positive() { self } else { other } } else { + // At least one input is NaN. Use `+` to perform NaN propagation and quieting. self + other } }