4 ms·
Neat trick. Math.pow(2, 53) == Math.pow(2, 53) + 1 This is a bit clearer I think. The addition just barely overflows the 53 mantissa bits of the IEEE 754
by johndough 5y ago
Neat trick.
Math.pow(2, 53) == Math.pow(2, 53) + 1
This is a bit clearer I think. The addition just barely overflows the 53 mantissa bits of the IEEE 754 double precision floating point number.
By the way, JS has BigInts these days, which are supported by all major browsers: https://caniuse.com/bigint https://caniuse.com/bigint
>> const x = 288230376151711740n;
>> x == x + 1n
false
- mirekrusin 5y ago2**53 == 2**53+1 ^^ even more clear. That's why Number.isSafeInteger(a) exists. Integers up to +/- 9007199254740991 (Number.MAX_SAFE_INTEGER) are fine.