From 964a7e52a8437a7613194f10eabe7a6c246501b3 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 27 Feb 2018 21:03:30 -0800 Subject: [PATCH] Reinstate NAN-sign fixes in FloatCore Formerly changed on the next branch, part of rust-num/num#319. --- src/float.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/float.rs b/src/float.rs index ae8df03..6d1fcdc 100644 --- a/src/float.rs +++ b/src/float.rs @@ -154,27 +154,28 @@ pub trait FloatCore: Num + NumCast + Neg + PartialOrd + Copy { /// - `FloatCore::nan()` if the number is `FloatCore::nan()` #[inline] fn signum(self) -> Self { - if self.is_sign_positive() { - return Self::one(); + if self.is_nan() { + Self::nan() + } else if self.is_sign_negative() { + -Self::one() + } else { + Self::one() } - if self.is_sign_negative() { - return -Self::one(); - } - Self::nan() } /// Returns `true` if `self` is positive, including `+0.0` and /// `FloatCore::infinity()`. #[inline] fn is_sign_positive(self) -> bool { - self > Self::zero() || (Self::one() / self) == Self::infinity() + !self.is_sign_negative() } /// Returns `true` if `self` is negative, including `-0.0` and /// `FloatCore::neg_infinity()`. #[inline] fn is_sign_negative(self) -> bool { - self < Self::zero() || (Self::one() / self) == Self::neg_infinity() + let (_, _, sign) = self.integer_decode(); + sign < 0 } /// Returns the minimum of the two numbers.