-
Notifications
You must be signed in to change notification settings - Fork 13k
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
IEEE754 non-conformance: is_sign_negative does not apply on NANs #42425
Comments
This program: fn main() {
let nums = [::std::f64::NEG_INFINITY, -1.0, -0.0, ::std::f64::NAN, 0.0, 1.0, ::std::f64::INFINITY];
for &num in &nums[..] {
println!("Number: {}\tSign negative: {}\tSign positive: {}", num, num.is_sign_negative(), num.is_sign_positive());
}
} prints the following output when compiled with current master and nightly:
What would be the expected result according to the standard? I would expect something that isn't a number to be neither negative nor positive, so I think the current results are correct? |
My reading of the spec suggests the answer should be equivalent to E.g. Section 6.2.1:
alludes to You can set the sign of |
Fix NaN handling in is_sign_negative/positive This would be my proposed fix for the #42425 provided we decide it is indeed a problem. Note this would technically be a breaking change to a stable API. We might want to consider deprecating these methods and adding new ones.
Isn't this fixed since #42431 was merged? |
41: Various improvements to FloatCore r=vks a=cuviper - New macros simplify forwarding method implementations. - `Float` and `Real` use this to compact their implementations. - `FloatCore` now forwards `std` implementations when possible. - `FloatCore` now requires `NumCast`, like `Float does. - New additions to `FloatCore`: - Constants like `min_value()` -> `f64::MIN` - Rounding methods `floor`, `ceil`, `round`, `trunc`, `fract` - `integer_decode` matching `Float`'s - Fix NAN sign handling in `FloatCore` (rust-num/num#312, rust-lang/rust#42425) - Fix overflow in `FloatCore::powi` exponent negation. - Add doctests to all `FloatCore` methods.
IEEE754 says
However our
is_sign_negative
/is_sign_positive
do not properly inspect the sign forNaN
s.The text was updated successfully, but these errors were encountered: