you think every implementation follows the spec properly? this is web browsers; today doesn't apply to last decade, where the constraints existed
-
-
Replying to @jasonmulligan
IEEE 754 predates web browsers. It came out in 1985. And besides, IEEE 754 is baked into CPUs anyway, so browsers aren't going to randomly mess it up. The only problem here is JS *lies* when converting to a string.
1 reply 0 retweets 0 likes -
Replying to @marcan42 @jasonmulligan
No other programming language does this. No other programming language takes a floating-point value representing an integer, and, when converting it to a string, says "you know what, I'm going to give you a different integer, without any indication that rounding has occurred".
1 reply 0 retweets 0 likes -
Replying to @marcan42
yeah, i know. i've been dealing with the oddness since the beginning... i'm not trying to defend it, just tried to point you at the 'why'. v8 has bigint now, and so does node 10.4.x afaik, so things are getting better (slowly, very slowly)
1 reply 0 retweets 0 likes -
Replying to @jasonmulligan
Yes, and hilariously, (4611686018427387904).toString() is "4611686018427388000" (the wrong answer), while BigInt(4611686018427388000).toString() is "4611686018427387904" (the right answer) (or it will be once Chrome catches up with the spec, right now it's an error).
1 reply 0 retweets 0 likes -
Replying to @marcan42
try `0x4000000000000000n` ;) ... the 'n' is important atm
1 reply 0 retweets 0 likes -
Replying to @jasonmulligan
Yes, my point is that BigInt's conversion (once relaxed; the standard got changed recently to allow converting floating-point integers >2^53) proves that the real underlying integer behind the float value is 4611686018427387904, not 4611686018427388000.
1 reply 0 retweets 0 likes -
Replying to @marcan42 @jasonmulligan
You can also get the right answer from toFixed(0) instead of toString():pic.twitter.com/6fNi1jj3rk
2 replies 0 retweets 1 like -
Replying to @marcan42 @jasonmulligan
Sadly there seems to be no way to get the true decimal integer representation of 1.7976931348623157e+308 without BigInt, because toFixed/toPrecision are limited to 100 digits, so we'll have to wait until Chrome is updated with the new spec. In the meantime, Python can do it.pic.twitter.com/dPcVjcOCCa
1 reply 0 retweets 0 likes -
Replying to @marcan42
toString is interesting for numbers http://es5.github.io/#x9.8.1
1 reply 0 retweets 0 likes
Yes, the big fuckup in that algorithm is the "21" threshold and logic in point 6. It should be set up so that as soon as the number is > 2^53, it breaks into point 9 and switches to e-notation, making it clear that we're past the safe integer threshold.
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.