Skip to content

Round-tripping of large numbers without decimals incorrect #75

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

Closed
gkellogg opened this issue Mar 24, 2019 · 3 comments
Closed

Round-tripping of large numbers without decimals incorrect #75

gkellogg opened this issue Mar 24, 2019 · 3 comments
Labels

Comments

@gkellogg
Copy link
Member

The Data Round Tripping section says that a number with no non-zero fractional part is a sequence if digits (0-9), and uses (value).toFixed(0).toString() as an example of how to perform such a conversion. However, for numbers larger than 9e20, this will use an exponential representation. For example 1e21 will serialize as 1e+21 using the javascript algorithm cited. Ruby serializes as an integer, but is inaccurate. For example 1e25.to_i is 10000000000000000905969664. This is due to the inherent inaccuracies of IEEE doubles. That's why JCS defers to ES6, with a substantially more complicated algorithm.

We should update the section to indicate that numbers with no fractional part that can be represented using an exponent less than or equal to 20 are represented as a sequence of digits, everything else is serialized as a double.

Note that we're still different than JCS, which may eventually be an issue, as a sign in the exponent, and we prohibit this.

cc/ @dlongley

@dlongley
Copy link
Contributor

This does sound like it needs to be tightened up. I'm less concerned about us deviating from ES6 to keep backwards compatibility when converting standalone integers to xsd:integer -- and more concerned about deviating from ES6 when converting entire JSON literals that happen to contain integers.

@pchampin
Copy link
Contributor

My 2¢: the criterion on the exponent seems quite arbitrary. If we go down that path, I'd rather put the limit at 2^64, which has roughly the same order of magnitude, but makes more sense in terms of internal representation.

But I also agree with @dlongley that we should tend to converge as much as possible with existing standards.

@gkellogg
Copy link
Member Author

Closed by #79.

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

No branches or pull requests

3 participants