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

int(9223372036854775807.5) == -9223372036854775808 #375

Closed
adonovan opened this issue May 5, 2021 · 0 comments · Fixed by #376 or #377
Closed

int(9223372036854775807.5) == -9223372036854775808 #375

adonovan opened this issue May 5, 2021 · 0 comments · Fixed by #376 or #377

Comments

@adonovan
Copy link
Collaborator

adonovan commented May 5, 2021

Due to inexact int/float comparison at https://github.com/google/starlark-go/blob/master/starlark/int.go#L427.

The root cause is that math.MaxInt64 0x7fffffffffffffff cannot be exactly represented as a float64 because it has more than 53 bits of precision, so the comparison f <= MaxInt64 actually compares f to the value float64(MaxInt64), which is numerically equal to MaxInt64+1, which of course cannot be exactly represented as an int64. So if f == MaxInt64 the condition is spuriously true. The fix is to add an extra check for this particular value.

Pointed out by @Algebra8 in https://github.com/google/starlark-go/pull/373/files/3aea0fb3460e9c3764a2d287b573fa1a0465a90d..a73eaa2e67bd3236c52f8ed9c0e22d36b7e8d510

adonovan added a commit that referenced this issue May 6, 2021
Instead of math.NextAfter, use a strict <.

Fixes #375
adonovan added a commit that referenced this issue May 6, 2021
Instead of math.NextAfter, use a strict <.

Fixes #375
adonovan added a commit that referenced this issue May 6, 2021
Instead of math.NextAfter, use a strict <.

Fixes #375
adonovan added a commit that referenced this issue May 7, 2021
Instead of math.NextAfter, use a strict <.

Fixes #375
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant