DEV Community

Discussion on: True or False: Math.pow(2, 53) == Math.pow(2, 53) + 1 ?

Collapse
 
maxrimue profile image
Max • Edited

At first, I was confused why this would not return false, but of course you wouldn't have posted this if it would return false. 😃

While looking into why these statements are evaluated to be equal, I stumbled upon an even more interesting problem: When you try to enter exceedingly big numbers into a JavaScript console, they will be returned similiarly but not with the exact same value. For example, 9007199254740992111 will be transformed into 9007199254740992000. This sounded awfully like floating point issues. After having a look, the way integers are stored in JavaScript engines using 64 bits, which means there's a limit to correctly display numbers above a certain threshold. And that threshold appears to be 2^53, which explains why you took those parameters for Math.pow!

Previously, I was only aware of examples where floating point issues arise with the storage of numbers smaller than zero, leading me to think it would be a "comma problem" (for example 0.1 + 0.2 != 0.3), but this example made clear for me that this of course can also happen for big numbers.

This thread helped me understand the details, it's worth checking out.