As stable as math can be

Then god said e=mc² and there has been light

We all want to believe that numbers, as the essential element of the computer, is a stable and safe subject. But…

The floating-point

0.1 + 0.2 != 0.3

Well, this is one of the most famous JavaScript edge cases. While changing the numbers to binary and back to decimals, the result gets extra value.

0.1 + 0.2 == 0.30000000000000004

The last safe number

Once we pass the last safe number.MAX_SAFE_INTEGER, As if we had passed the horizon of a black hole, all mathematical rules start to break.

9007199254740991 + 1 == 9007199254740992
// x + 1 == x + 1

9007199254740991 + 2 == 9007199254740992
// x + 1 == x + 2

9007199254740991 + 3 == 9007199254740994

9007199254740991 + 4 == 9007199254740996
// x + 4 == x + 5

9007199254740991 * 1   ==   9007199254740991
9007199254740991 * 10  ==  90071992547409900
9007199254740991 * 100 == 900719925474099100

9999999999999999 == 10000000000000000

NaN has no identaty

parseInt('d') != parseInt('d')

Looks funny, but since NaN is not a number, NaN != NaN.

Beyond Infinity

As known, once you pass infinity, everything just starts over. Though as expected:

-Infinity < Infinity
Number.NEGATIVE_INFINITY < Number.POSITIVE_INFINITY

-Infinity == Number.NEGATIVE_INFINITY
 Infinity == Number.POSITIVE_INFINITY

Somehow:

Math.max() < Math.min()

Math.max() === -Infinity
Math.max() === Number.NEGATIVE_INFINITY

Math.min() == Infinity
Math.min() == Number.POSITIVE_INFINITY

Conclusion, next time your math teacher tells you that you are wrong, write a simple JavaScript program to prove that 1+1 != 2 from there everything is possible.