-
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
Deterministic int to float conversion #62175
Comments
This might just be a bug in the reference. rustc probably just emits |
Some discussion in rust-lang/reference#607. |
Further discussion in https://internals.rust-lang.org/t/tryfrom-for-f64/9793 |
Discussed in @rust-lang/lang meeting and @joshtriplett will try to follow up with this as well as rust-lang/reference#607. |
Is this something that would naturally vary between targets? Would specifying this break any existing or anticipated targets? If the answer to both questions is "no", then I'm fine with specifying this. If we don't currently have consistent behavior on this point across all our existing targets, then I don't think the standard should precede the implementation here. |
This appears to be resolved, so this issue can be closed. (The reference now specifies the rounding mode. See rust-lang/reference#607.) |
Casting from an integer type to a floating point type leaves the rounding behavior explicitly unspecified. Is there (or are there plans for) some way of deterministically turning an int into a float regardless of the target architecture? I really don't want
9007199254740993u64 as f64
to be converted to9007199254740992.0
on one machine and9007199254740994.0
on another (the example u64 is 2^53 + 1, the smallest natural number not precisely representable as an f64).Options could be to either use the floating point rounding mode (interpreting the int as real number and then rounding it to the next representable float just like the semantics of all IEEE754 float operations), or supporting explicit rounding modes.
Apologies if such a feature already exists and I just didn't find it.
The text was updated successfully, but these errors were encountered: