1

The IEEE-754 standard states that when overflow occurs, the result may evaluate to either Infinity or MAX_VALUE. As I've been recommended a few times already I decided to see what ECMAScript standard says about it. I found this under Applying the Additive Operators to Numbers

If the magnitude is too large to represent, the operation overflows and the result is then an infinity of appropriate sign.

But testing it gives MAX_VALUE instead of Infinity, why?

Number.MAX_VALUE+100000000 // evaluates to Number.MAX_VALUE

However, this evaluates to Infinity:

Number.MAX_VALUE+Number.MAX_VALUE // evaluates to Infinity
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • I don't know for certain, but I'm guessing it has to do with the approximation of that value and the loss of precision allowing it to represent a large set of values. –  Oct 15 '16 at 13:11
  • @squint, yeah, that's what I'm thinking myself, but it's interesting how and why the decision to round the result or to store as Infinity is made – Max Koretskyi Oct 15 '16 at 13:14
  • If you add `Number.MAX_VALUE + Math.pow(10, 291)`, you don't get `Infinity`, but you do with `Number.MAX_VALUE + Math.pow(10, 292)`. The power of ten was arrived at by taking the value `1.7976931348623157e+308` and removing the shown decimal places from the 308. –  Oct 15 '16 at 13:14

0 Answers0