From e017595968e57c8ebd77f842cbea2893c08ce87a Mon Sep 17 00:00:00 2001 From: ud2 Date: Mon, 24 Nov 2025 05:09:05 +0800 Subject: [PATCH] Reduce code size of `{f32,f64}::is_finite` --- library/core/src/num/f32.rs | 5 ++--- library/core/src/num/f64.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/library/core/src/num/f32.rs b/library/core/src/num/f32.rs index 3070e1dedbe43..7e31d31daea1f 100644 --- a/library/core/src/num/f32.rs +++ b/library/core/src/num/f32.rs @@ -578,10 +578,9 @@ impl f32 { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")] #[inline] + #[allow(clippy::eq_op)] pub const fn is_finite(self) -> bool { - // There's no need to handle NaN separately: if self is NaN, - // the comparison is not true, exactly as desired. - self.abs() < Self::INFINITY + self - self == self - self } /// Returns `true` if the number is [subnormal]. diff --git a/library/core/src/num/f64.rs b/library/core/src/num/f64.rs index dc8ccc551b2da..542ed0d6045ab 100644 --- a/library/core/src/num/f64.rs +++ b/library/core/src/num/f64.rs @@ -577,10 +577,9 @@ impl f64 { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_float_classify", since = "1.83.0")] #[inline] + #[allow(clippy::eq_op)] pub const fn is_finite(self) -> bool { - // There's no need to handle NaN separately: if self is NaN, - // the comparison is not true, exactly as desired. - self.abs() < Self::INFINITY + self - self == self - self } /// Returns `true` if the number is [subnormal].