You work on TC39, so suggestion: change toString so that any numbers ≥ 2⁵³ or ≤ -2⁵³ are stringified in e-notation, or, alternatively, with the full integer digit expansion and a trailing ".". This makes it clear when precision is limited, without phantom/incorrect digits.
-
-
Replying to @marcan42 @kentaromiura and
I doubt that’s feasible. I bet it would break lots of existing code.
@littledan1 reply 0 retweets 0 likes -
toString always outputs a string which, when parsed as a Number, rounds to the same value. There are multiple strings which would round to the same Number. I think ending it with a bunch of 0's is often more intuitive, which would motivate that choice.
1 reply 0 retweets 1 like -
Replying to @littledan @mathias and
If you'd like to see the fun floating point bits, if you're trying to learn how floats work, you can do that with Number.prototype.toPrecision, toExponential, toFixed, which omit the logic to put 0's at the end.
1 reply 0 retweets 0 likes -
Replying to @littledan @mathias and
My issue is the lack of any evidence that the number is a float; that rounding occurred. JS is in the awkward position of using floats for the use cases of ints. Presumably this drove the decision to have toString output just digits when the float is an exact integer value.
1 reply 0 retweets 0 likes -
Replying to @marcan42 @littledan and
But then toString goes and *rounds* larger ints - at which point they're not floats trying to be ints any more - yet it still outputs just digits. And that is just confusing and messy.
1 reply 0 retweets 0 likes -
Replying to @marcan42 @littledan and
Sure, there are ways to get the full value out. My point here is that the default behavior is unintuitive and misleading in this particular case. Nobody expects an integer to have been rounded. Having to deal with the 53-bit ceiling is bad enough; toString hiding it is worse!
1 reply 0 retweets 1 like -
Unfortunately, the fact that JavaScript Numbers are IEEE 64-bit floats is just something JS devs will have to learn. I don't think toString is hiding anything here--ending in a bunch of zeros implies not as much precision as if it ended in a lot of non-zero digits.
2 replies 0 retweets 1 like -
This Tweet is unavailable.
-
Replying to @dougallj @littledan and
This is even worse than I thought. So it isn't even consistent about how many digits it rounds to. It just rounds as much as it can get away with for any *specific* number. 00→00 08→10 16→20 24→24 32→30 40→40 48→50 56→56 64→60 72→70 80→80 88→90 96→100 WTF.
1 reply 0 retweets 4 likes
I like the "60" case, which is exactly in between two actual values. So to interpret JS's toString output and undo the damage you not only need to know what precision you're dealing with exactly, but also float rounding edge case rules. I don't even.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.