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

Incorrect float→int conversion #973

Closed
dhardy opened this issue May 1, 2020 · 1 comment
Closed

Incorrect float→int conversion #973

dhardy opened this issue May 1, 2020 · 1 comment

Comments

@dhardy
Copy link
Member

dhardy commented May 1, 2020

fn to_u64(self) -> Option<u64> {
if self >= 0. && self <= ::core::u64::MAX as f64 {
Some(self as u64)
} else {
None
}
}

This function is wrong; to copy my comment from #958:

This is incorrect for 32-bit platforms. Check this out.

This isn't your fault; to_u64 for f64 makes the same mistake. Hmm, even the TryFrom in Rust 1.34 doesn't handle this conversion. I'm starting to hate this topic; seems simple but isn't.

@dhardy
Copy link
Member Author

dhardy commented Oct 19, 2020

The offending code was removed in #987 (including uses of it, so there is no replacement).

@dhardy dhardy closed this as completed Oct 19, 2020
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

No branches or pull requests

1 participant