Skip to content

Reduce safe integer range to exclude +/- 2^53 and match JavaScript safe-integer bounds #1240

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

Merged

Conversation

johnbartholomew
Copy link
Collaborator

As noted in #1217 (comment) and discussed in #1238.

Although 2^53 is representable (there is a bit-pattern for a IEEE-754 double precision float which represents this value), it is not safe because as @CertainLach pointed out, it is ambiguous/not distinguishable from 2^53+1 which is not representable and would be rounded down.

This also switches from a StaticError to a RuntimeError when encounting a non-integer-safe value since these values are runtime constructs not parse time (static).

@CertainLach if you have time to review, I'd appreciate it.

Fixes #1238.

Copy link
Contributor

@CertainLach CertainLach left a comment

Choose a reason for hiding this comment

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

LGTM (I misunderstood the test twice initially)

@johnbartholomew
Copy link
Collaborator Author

LGTM (I misunderstood the test twice initially)

That sounds like the tests need some more work. I'll see if I can improve it before merging.

@He-Pin
Copy link

He-Pin commented May 13, 2025

@johnbartholomew
Copy link
Collaborator Author

That sounds like the tests need some more work. I'll see if I can improve it before merging.

In an event that probably does not surprise anyone, I did not get time to do this so I'm going to merge now, and then work on further improvements 🫤

@johnbartholomew johnbartholomew force-pushed the fix-safe-integer-range branch from 9553eaf to 52ce23a Compare May 22, 2025 11:47
@johnbartholomew johnbartholomew merged commit 52ce23a into google:master May 22, 2025
7 checks passed
@johnbartholomew johnbartholomew deleted the fix-safe-integer-range branch June 19, 2025 12:39
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.

BUG: Defined safe integer range is invalid
3 participants