Basically, this is because 64 bits (*) are not enough to accurately represent a number.
4341 A521 1037 32ED : 9.93327205727586 6 ⨉ 10 154341 A521 1037 32EE : 9.93327205727586 8 ⨉ 10 15
See how it misses the whole between them. In IEEE 754, the higher you go, the more numbers are scattered across the number line. Keep in mind that floating point numbers are approximations. This is why you get this result:
0.1 + 0.2 === 0.3 // false
The maximum safe integer in IEEE 754 is 9007199254740991.
More interesting facts with floating point arithmetic:
A + B == B + A // true, commutative, except when A or B is NaN (A + B) + C == A + (B + C) // false, not associative
* It is worth noting that numbers in JavaScript (ECMAScript) are represented as 64-bit IEEE 754 doubles. ref
Derek 朕 會 功夫
source share