DEV Community

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

Collapse
 
mike239x profile image
Mike Lezhnin

Welp, I actually expected JS to behave same way as python and produce false. I've never been so wrong.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

Yeah, Python doesn't tell you about short, long, float and double and it automates this; but for JavaScript, it is always double.

I am actually stumbled in standard Python that it is False, instead of throwing an error. It will not be the case in Kotlin.

>>> 2 ** 64 == 2 ** 64 + 1
False
>>> type(2 ** 64 + 1)
<class 'int'>

Now, I can ask on StackOverflow, but SO is such as scary place. There is this in Quora, but not many wants to answer.

It seems that it is bignum, actually. You don't even have to care about Decimal, unless you care about 0.1 + 0.2