-
Notifications
You must be signed in to change notification settings - Fork 148
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
Fix float to int cast overflow #135
Conversation
feel free to critique |
@@ -1136,30 +1136,42 @@ macro_rules! impl_to_primitive_float_to_float { | |||
) | |||
} | |||
|
|||
macro_rules! impl_to_primitive_float_to_int_or_uint { |
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.
(bikeshed) I'd just call it ..._to_integer
.
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.
sure, I'll change it.
Sorry, I didn't notice you pushed an update for truncation. That looks good. On the importance of edge cases, consider something like 2^64, which should be
The true maximum that can be converted is actually less than If only |
Hey, after his update I did some more testing and realized that my implementation had gaps (which you also found) and I didn't find the time to really dive in again and fix it completely. I'll have another look this week. |
If you don't want to hardcode significand-based MIN/MAX values, another possibility is to just check the round-trip. Something like:
But I'd still want those significand edge-cases tested, so we need those values anyway. |
☔ The latest upstream changes (presumably ebed675) made this pull request unmergeable. Please resolve the merge conflicts. |
We should still fix this, but this PR is long stagnant. See the new repo and issue here: |
fix #119