You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
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 than9e20
, this will use an exponential representation. For example1e21
will serialize as1e+21
using the javascript algorithm cited. Ruby serializes as an integer, but is inaccurate. For example1e25.to_i
is10000000000000000905969664
. 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
The text was updated successfully, but these errors were encountered: