0
console.log(Number.MIN_VALUE);  // 5e-324
console.log(Number.MIN_VALUE - 1); // -1

Value of Number.MIN_VALUE is 5e-324, but if I subtract 1 from it, -1 is returned.

It looks like some garbage value but I'm wondering why JavaScript interpreter cannot represent it. Otherwise, Number.MAX_VALUE + 1 is same with Number.MAX_VALUE(1.7976931348623157e+308).

Is there something different between calculating Numbers.MAX_VALUE and Numbers.MIN_VALUE?

EnDelt64
  • 1,270
  • 3
  • 24
  • 31

1 Answers1

1

Number.MIN_VALUE - 1 is equal to -0.99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

I think any reasonable person would consider that to be -1, even before accounting for things like floating point inaccuracy :)

To be clear, Number.MIN_VALUE is the smallest value greater than zero that can be represented. It is not "negative Number.MAX_VALUE" as you appear to expect.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592