-
Notifications
You must be signed in to change notification settings - Fork 92
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
Add support for float_to_int_unchecked #3660
Add support for float_to_int_unchecked #3660
Conversation
Please don't forget to update |
Thanks for the reminder. Added. |
This PR could use quite a bit of cleanup, especially around hard-coded values and unit tests. In particular, it's probably better to store the hard-coded values using their byte representation as opposed to their decimal one. |
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.
Should we be worried about the cast using as
logic?
I did a fairly big overhaul of the PR in 08531f6:
@celinval This should address some of your comments. |
I'm really sorry, I think you might've misunderstood my comment about the My comment about the |
Not at all. I was planning to make this change before your comment. The reason is that casting a decimal value into a floating-point value can have surprising behavior. For example, this program: println!("{}", u32::MAX);
let f1: f32 = u32::MAX as f32;
let f2: f32 = u32::MAX as f32 + 1.0;
let f3: f32 = (u32::MAX as u128 + 1) as f32;
println!("{:.32}", f1);
println!("{:.32}", f2);
println!("{:.32}", f3); prints:
So casting the decimal value https://www.h-schmidt.net/FloatConverter/IEEE754.html One way to specify a floating-point value unambiguously is to use the byte representation. This is the reason I switched to it. |
I made a few final touches:
@tautschnig @celinval Let me know if you want to take another look. Otherwise, I'll go ahead and merge. |
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.
It's fine by me. Thanks!
This PR adds support for the
float_to_int_unchecked
intrinsic forf32
andf64
.Towards #3629
Keeping it as draft till I add more tests.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.