Question

This code snippet:

Math.pow(10,20)+20000 == Math.pow(10,20) + 10000

evaluates to true. Is this a JS bug?

Was it helpful?

Solution

No. Javascript uses floating point numbers to represent large values, and the value 1020 exceeds the precision of the floating point numbers. When you add a relatively tiny value such as 20000 or 10000 to the result, the resulting sums are indistinguishable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top