-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
copysign with sign being a NaN can have non-portable results #129683
Conversation
rustbot has assigned @workingjubilee. Use |
Doesn't |
Yes, it does work on the bit level. That is already documented:
|
The point isn't that |
The NaN bit pattern docs don't mention what operations are arithmetic operations. |
LGTM |
The following should be consistent, right, even if it isn't specified what the values are? let nan = f32::NAN;
let sign_a = 1.0_f32.copysign(nan);
let sign_b = 1.0_f32.copysign(f32::from_bits(nan.to_bits()));
assert_eq!(sign_a, sign_b); |
@workingjubilee yes, |
Then we should document that some operations are non-arithmetic operations and what they are. |
The NaN rules apply to all float operations except the "bitwise" ones, unless the operation documents something different. The docs do say which ones are "bitwise". So the use of "arithmetic" in these docs here isn't very meaningful I think -- but I didn't introduce that term into the docs so I am not sure what the original author intended that term to mean. |
I suspect they meant the set that doesn't include |
That's what IEEE754 would say, anyways. I bring this up because that's the precise set we're declaring as having inconstant results, essentially. |
Sure! I am mostly making sure that there's no objection to clarifying this matter further, because I know that even if we "get it", I don't think it will be understood implicitly by everyone. |
copysign with sign being a NaN can have non-portable results Follow-up to rust-lang#129559. Cc `@tgross35` `@beetrees` There's no portable variant we can recommend instead here, is there? Something with a semantics like "if `sign` is a NaN, then return `self` unaltered, otherwise return `self` with the sign changed to that of `sign`"?
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods) - rust-lang#129170 (Add an ability to convert between `Span` and `visit::Location`) - rust-lang#129366 (linker: Synchronize native library search in rustc and linker) - rust-lang#129467 (derive(SmartPointer): assume pointee from the single generic and better error messages) - rust-lang#129494 (format code in tests/ui/threads-sendsync) - rust-lang#129527 (Don't use `TyKind` in a lint) - rust-lang#129617 (Update books) - rust-lang#129673 (Add fmt::Debug to sync::Weak<T, A>) - rust-lang#129683 (copysign with sign being a NaN can have non-portable results) - rust-lang#129689 (Move `'tcx` lifetime off of impl and onto methods for `CrateMetadataRef`) - rust-lang#129695 (Fix path to run clippy on rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
copysign with sign being a NaN can have non-portable results Follow-up to rust-lang#129559. Cc ``@tgross35`` ``@beetrees`` There's no portable variant we can recommend instead here, is there? Something with a semantics like "if `sign` is a NaN, then return `self` unaltered, otherwise return `self` with the sign changed to that of `sign`"?
…kingjubilee Rollup of 14 pull requests Successful merges: - rust-lang#128192 (rustc_target: Add various aarch64 features) - rust-lang#129170 (Add an ability to convert between `Span` and `visit::Location`) - rust-lang#129343 (Emit specific message for time<=0.3.35) - rust-lang#129378 (Clean up cfg-gating of ProcessPrng extern) - rust-lang#129401 (Partially stabilize `feature(new_uninit)`) - rust-lang#129467 (derive(SmartPointer): assume pointee from the single generic and better error messages) - rust-lang#129494 (format code in tests/ui/threads-sendsync) - rust-lang#129617 (Update books) - rust-lang#129673 (Add fmt::Debug to sync::Weak<T, A>) - rust-lang#129683 (copysign with sign being a NaN can have non-portable results) - rust-lang#129689 (Move `'tcx` lifetime off of impl and onto methods for `CrateMetadataRef`) - rust-lang#129695 (Fix path to run clippy on rustdoc) - rust-lang#129712 (Correct trusty targets to be tier 3) - rust-lang#129715 (Update `compiler_builtins` to `0.1.123`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129683 - RalfJung:copysign, r=thomcc copysign with sign being a NaN can have non-portable results Follow-up to rust-lang#129559. Cc ```@tgross35``` ```@beetrees``` There's no portable variant we can recommend instead here, is there? Something with a semantics like "if `sign` is a NaN, then return `self` unaltered, otherwise return `self` with the sign changed to that of `sign`"?
Follow-up to #129559.
Cc @tgross35 @beetrees
There's no portable variant we can recommend instead here, is there? Something with a semantics like "if
sign
is a NaN, then returnself
unaltered, otherwise returnself
with the sign changed to that ofsign
"?