Skip to content
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 -> u128 conversion bug #14

Merged
merged 3 commits into from
May 7, 2017
Merged

Conversation

est31
Copy link
Contributor

@est31 est31 commented May 7, 2017

Converting floats to u128 failed because in the comparison
"src > u128::MAX as f32" we invoked UB due to the
u128::MAX as f32 conversion.

@est31
Copy link
Contributor Author

est31 commented May 7, 2017

See also rust-lang/rust#41799

Converting floats to u128 failed because in the comparison
"src > u128::MAX as f32" we invoked UB due to the
u128::MAX as f32 conversion.
@est31
Copy link
Contributor Author

est31 commented May 7, 2017

r? @japaric

and of course, I'll need a new version

@@ -302,6 +302,37 @@ macro_rules! from_float {
}
}

/// From a float `$src` to an integer `$dst`, where $dst is large enough to contain
/// all values of `$src`. We can't ever overflow here
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't ever overflow here

Overflow can happen when going from f32 to i128

f32::MAX = 340282350000000000000000000000000000000
i128::MAX = 170141183460469231731687303715884105727

} else if src == $src::INFINITY ||
src == $src::NEG_INFINITY {
Error::Infinite
} else if ($dst::MIN == 0) && src < 0.0 {
Copy link
Owner

@japaric japaric May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underflow can happen when going from f32 to i128

f32::MIN = -340282350000000000000000000000000000000
i128::MIN = -170141183460469231731687303715884105728

@est31
Copy link
Contributor Author

est31 commented May 7, 2017

re-r? @japaric

@japaric
Copy link
Owner

japaric commented May 7, 2017

@homunkulus r+

@homunkulus
Copy link
Collaborator

📌 Commit 868978e has been approved by japaric

@homunkulus
Copy link
Collaborator

⌛ Testing commit 868978e with merge 868978e...

@homunkulus
Copy link
Collaborator

💔 Test failed - status-travis

@japaric
Copy link
Owner

japaric commented May 7, 2017

@homunkulus r+

@homunkulus
Copy link
Collaborator

📌 Commit d492df1 has been approved by japaric

@homunkulus
Copy link
Collaborator

⌛ Testing commit d492df1 with merge d492df1...

@homunkulus
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: japaric
Pushing d492df1 to master...

@homunkulus homunkulus merged commit d492df1 into japaric:master May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants