-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remap issues when converting between an Integer and a Float #5530
Comments
@FungusHumungus this appears to be very edge-casey, correct? And what would the solution be if we wanted to solve this? |
@binarylogic It means our arithmetic functions fall over at large numbers (integers greater than 2^52 - I think). I'm not really sure what the solution is. Am currently reading through the chapter in Hackers Delight on it to see if I can get any inspiration. I think it would be worth asking the rest of the team next week to see if anyone has any ideas.. It might be that it's not really something anyone would ever really need to worry about, so perhaps just documenting it will suffice. |
@FungusHumungus I just realised the changes in #5663 didn't mark division as a fallible operation, which it should because we don't know at compile-time if the rhs value will be zero or not. |
Here's a test-case that passes, which it shouldn't because the error isn't handled at compile-time:
|
Here's another one that passes, again it shouldn't because I should be able to capture the error (this is because of the incorrect type def):
|
Remap has two numeric types
Integer
andFloat
. When performing arithmetic Rust requires both types to be the same, so Remap often needs to cast the types to ensure they are the same. Casting a number between a float and an integer doesn't always result in the same value.For example:
Casting
36,028,797,018,963,968
as i64 to f64 results in36,028,797,018,963,970
. (Note the last two digits differ.) The converse is also true -36,028,797,018,963,970
as f64 to i64 goes back to36,028,797,018,963,968
.Casting
4,052,555,153,018,976,267
as i64 to f 64 results in4,052,555,153,018,976,000
. Casting that number back to i64 results in4,052,555,153,018,976,256
.This can result in inaccurrate calculations at large values.
It can also produce surprising results. For example, in Remap:
1 * (1 / 0) == 9,223,372,036,854,775,807
In the above, for
1 / 0
both numbers are cast to a float. The result isinfinity
. When multiplying by 1 - since 1 is an integer, both numbers are cast to i64.infinity
as i64 is9,223,372,036,854,775,807
- (111111111111111111111111111111111111111111111111111111111111111
).The text was updated successfully, but these errors were encountered: