diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2017-06-04 21:44:57 +0300 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2017-06-22 23:12:01 +0300 |
| commit | 3b9fe77bfcd4c800fab8afcdcc82d31facdc515b (patch) | |
| tree | 464db7167313be8d61001eabd038521e9fcf0d0e /src/libstd/f32.rs | |
| parent | 0da9721ab49d80bf74208e94a891b12c4a248507 (diff) | |
| download | rust-3b9fe77bfcd4c800fab8afcdcc82d31facdc515b.tar.gz rust-3b9fe77bfcd4c800fab8afcdcc82d31facdc515b.zip | |
Fix NaN handling in is_sign_negative/positive
See #42425
Diffstat (limited to 'src/libstd/f32.rs')
| -rw-r--r-- | src/libstd/f32.rs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 4abad7e24f8..2f5a7c72411 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -365,39 +365,29 @@ impl f32 { #[inline] pub fn signum(self) -> f32 { num::Float::signum(self) } - /// Returns `true` if `self`'s sign bit is positive, including - /// `+0.0` and `INFINITY`. + /// Returns `true` if and only if `self` has a positive sign, including `+0.0`, `NaN`s with + /// positive sign bit and positive infinity. /// /// ``` - /// use std::f32; - /// - /// let nan = f32::NAN; /// let f = 7.0_f32; /// let g = -7.0_f32; /// /// assert!(f.is_sign_positive()); /// assert!(!g.is_sign_positive()); - /// // Requires both tests to determine if is `NaN` - /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn is_sign_positive(self) -> bool { num::Float::is_sign_positive(self) } - /// Returns `true` if `self`'s sign is negative, including `-0.0` - /// and `NEG_INFINITY`. + /// Returns `true` if and only if `self` has a negative sign, including `-0.0`, `NaN`s with + /// negative sign bit and negative infinity. /// /// ``` - /// use std::f32; - /// - /// let nan = f32::NAN; /// let f = 7.0f32; /// let g = -7.0f32; /// /// assert!(!f.is_sign_negative()); /// assert!(g.is_sign_negative()); - /// // Requires both tests to determine if is `NaN`. - /// assert!(!nan.is_sign_positive() && !nan.is_sign_negative()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -1186,7 +1176,7 @@ mod tests { assert!(!nan.is_infinite()); assert!(!nan.is_finite()); assert!(!nan.is_normal()); - assert!(!nan.is_sign_positive()); + assert!(nan.is_sign_positive()); assert!(!nan.is_sign_negative()); assert_eq!(Fp::Nan, nan.classify()); } @@ -1430,7 +1420,8 @@ mod tests { assert!(!(-1f32).is_sign_positive()); assert!(!NEG_INFINITY.is_sign_positive()); assert!(!(1f32/NEG_INFINITY).is_sign_positive()); - assert!(!NAN.is_sign_positive()); + assert!(NAN.is_sign_positive()); + assert!(!(-NAN).is_sign_positive()); } #[test] @@ -1443,6 +1434,7 @@ mod tests { assert!(NEG_INFINITY.is_sign_negative()); assert!((1f32/NEG_INFINITY).is_sign_negative()); assert!(!NAN.is_sign_negative()); + assert!((-NAN).is_sign_negative()); } #[test] |
