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()`
#[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.