-
Notifications
You must be signed in to change notification settings - Fork 149
Fix float NaN positive/negative assumptions #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,8 +323,8 @@ pub trait Float | |
/// ``` | ||
fn signum(self) -> Self; | ||
|
||
/// Returns `true` if `self` is positive, including `+0.0` and | ||
/// `Float::infinity()`. | ||
/// Returns `true` if `self` is positive, including `+0.0`, | ||
/// `Float::infinity()`, and `f64::NAN` with newer versions of Rust. | ||
/// | ||
/// ``` | ||
/// use num_traits::Float; | ||
|
@@ -337,27 +337,25 @@ pub trait Float | |
/// | ||
/// 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()); | ||
/// assert!(!nan.is_sign_negative()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, we should be testing |
||
/// ``` | ||
fn is_sign_positive(self) -> bool; | ||
|
||
/// Returns `true` if `self` is negative, including `-0.0` and | ||
/// `Float::neg_infinity()`. | ||
/// Returns `true` if `self` is negative, including `-0.0`, | ||
/// `Float::neg_infinity()`, and `-f64::NAN` with newer versions of Rust. | ||
/// | ||
/// ``` | ||
/// use num_traits::Float; | ||
/// use std::f64; | ||
/// | ||
/// let nan = f64::NAN; | ||
/// let neg_nan: f64 = -f64::NAN; | ||
/// | ||
/// let f = 7.0; | ||
/// let g = -7.0; | ||
/// | ||
/// 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()); | ||
/// assert!(!neg_nan.is_sign_positive()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And this doctest should have the |
||
/// ``` | ||
fn is_sign_negative(self) -> bool; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any ideas on how to make this less confusing? Right now it's not clear what "newer versions of Rust" applies to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM ".., and with newer versions of Rust
f64::NAN
" works.