Domanda

This code snippet:

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

evaluates to true. Is this a JS bug?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top