Reinstate NAN-sign fixes in FloatCore

Formerly changed on the next branch, part of rust-num/num#319.
This commit is contained in:
Josh Stone 2018-02-27 21:03:30 -08:00
parent 8d16921579
commit 964a7e52a8
1 changed files with 9 additions and 8 deletions

View File

@ -154,27 +154,28 @@ pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy {
/// - `FloatCore::nan()` if the number is `FloatCore::nan()` /// - `FloatCore::nan()` if the number is `FloatCore::nan()`
#[inline] #[inline]
fn signum(self) -> Self { fn signum(self) -> Self {
if self.is_sign_positive() { if self.is_nan() {
return Self::one(); 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 /// Returns `true` if `self` is positive, including `+0.0` and
/// `FloatCore::infinity()`. /// `FloatCore::infinity()`.
#[inline] #[inline]
fn is_sign_positive(self) -> bool { 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 /// Returns `true` if `self` is negative, including `-0.0` and
/// `FloatCore::neg_infinity()`. /// `FloatCore::neg_infinity()`.
#[inline] #[inline]
fn is_sign_negative(self) -> bool { 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. /// Returns the minimum of the two numbers.