-
Notifications
You must be signed in to change notification settings - Fork 2
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
Exact casts from float to int? #8
Comments
They're not missing, they're just written differently: Yes, |
Ah yes, I'd forgotten. Apologies. Could we add Maybe Feel free to close this as wontfix, which is probably the right answer. Again, apologies. |
But what number? 🙂 I had a guess that turned out to be right, since there's only one "reasonable" choice; the Rust reference confirms it as canon. Ugh. I mean, I guess the Romans thought it was not a number, which should be good enough for me. Off-topic, but I find the whole thing as funny as it is sad. Very grateful for your work on this crate, which I plan to use as my go-to tool for numeric conversions henceforth. |
It's a bit too easy to end up with floats that are not quite ints though IMO, e.g.: fn main() {
let x = (1.0 - 0.9) * 10.0;
println!("{}", x);
println!("x == 1: {}", x == 1.0);
}
Any number? Define |
So...
Technically, yes. Practically, I'm not sure if it's sufficiently useful. Perhaps we'll see if there are further requests / justifications.
This isn't an approximate-equality library so my gut feeling is that it doesn't belong here, though that's not a big thing to add. |
Unless I'm missing something, casts from float to int are currently missing. This is too bad, as these are some of the most problematic casts(Edit: I was missing something. See below.)as
provides.Suggested semantics are to only convert from floats that are exact integers (only zero bits after the decimal point) that will fit in the target int.
No prize for guessing what Rust does with
(0.0f32 / 0.0) as u32
. 🙂The text was updated successfully, but these errors were encountered: