-
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
Rust does not specify IEEE 754 rounding mode for signed zero #116339
Comments
IMO this is just a docs bug, where we were overly strict by specifying that the rounding mode only matters when the result "is not exactly representable". Patches should be welcome. |
I agree, there is no reasonable world in which we'll use a different behavior for signed zero than what IEEE 754 prescribes for roundTiesToEven. What would better wording be? |
Something along the lines of "is not exactly representable as a distinct f32" perhaps? |
@thomcc I made a PR with an alternate wording I like. It simply drops any condition on rounding, simply stating we use the roundTiesToEven rounding mode, and clarifying what happens with sums. "The result is the representable value closest to the true value, if there is a unique closest representable value." also perfectly covers any result that doesn't need to be rounded, so no harm in dropping the condition. |
Rollup merge of rust-lang#116355 - orlp:signed-zero-rounding-mode, r=thomcc Clarify float rounding direction for signed zero Closes rust-lang#116339.
Location
https://doc.rust-lang.org/std/primitive.f32.html
Summary
The Rust documentation on
f32
states (emphasis mine):However, this does not specify the behavior for
-0.0f32 + 0.0f32
. This value is exactly representable, the issue is in fact that it is representable in two ways. According to the IEEE754-2019 standard the behavior should be:In other words, the behavior depends on the rounding mode. We should specify that in this scenario we also follow the roundTiesToEven rounding mode, that is, the result of
-0.0f32 + 0.0f32
should be0.0f32
.The text was updated successfully, but these errors were encountered: