質問

This code snippet:

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

evaluates to true. Is this a JS bug?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top