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

int64 validation is incorrect #90

Open
klntsky opened this issue Feb 22, 2024 · 1 comment
Open

int64 validation is incorrect #90

klntsky opened this issue Feb 22, 2024 · 1 comment

Comments

@klntsky
Copy link

klntsky commented Feb 22, 2024

// JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64

// JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64

The second part of the sentence does not follow from the first. Neither JS nor JSON do not throw on overflows.

Consider this:

> Number.isInteger(JSON.parse('' + (2 ** 65)))
true
@klntsky
Copy link
Author

klntsky commented Feb 22, 2024

I'm not familiar with the overflow behavior in JS, but letting it overflow on platforms that don't support long integers and perform the exact comparison on platforms that do would seemingly be better.

This is not a proposed fix, just an illustration of the idea:

> (JSON.parse('' + (2 ** 63))) < 2 ** 64
true
> (JSON.parse('' + (2 ** 64))) < 2 ** 64
false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant