43

Using Node.js, I'm evaluating the expression:

0 < Number.MIN_VALUE

To my surprise, this returns true. Why is that? And: How can I get the smallest number available for which the comparison works as expected?

3
  • 4
    Number.MIN_SAFE_INTEGER Commented Oct 28, 2014 at 17:32
  • @Vohuman: but isn't zero greater than all negative numbers? Commented Oct 28, 2014 at 17:32
  • Number.MIN_SAFE_INTEGER is undefined in Node.js 0.10.x. Commented Oct 28, 2014 at 17:38

5 Answers 5

64

Number.MIN_VALUE is 5e-324, i.e. the smallest positive number that can be represented within float precision, i.e. that's as close as you can get to zero. It defines the best resolution floats give you.

Now the overall smallest value is Number.NEGATIVE_INFINITY although that's not really numeric in the strict sense.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for explaining the behavior and pointing out a viable alternative :-)
I can't believe I actually had to look this up to find out why my code was wrong. I swear, javascript, sometimes...
I would say Number.NEGATIVE_INFINITY is the least value (in the sense that no other values can be lesser), but not the smallest. The word "small" implies a small quantity, i.e. a value closer to 0, and "large" implies a value farther away from zero (-1000 is "larger" than 10). So in that sense, -Infinity is quite large, even if it is negative.
6

Number.MIN_VALUE is equivalent to 5e-324 , which is greater than 0.

1 Comment

This is true. I think what's throwing people off is the negative exponent -324. I taught high schoolers who thought that 3 ** -2 === -9.
2

Since Number.MIN_VALUE = 5e-324 = 5 x 10^-324 and it's greater than 0(a little bit greater).
Read more here.

2 Comments

Number.MIN_SAFE_INTEGER is undefined in Node.js 0.10.x.
Yes, sometimes people forget e notation. A positive number raised to a negative exponent is still positive. I taught high schoolers who thought that 3 ** -2 === -9.
1
`Number.MIN_VALUE` is equal to 5e-324 or 5*(10^-324);

it's math. any positive number is greater than zero.

Comments

-1

Use -Number.MAX_VALUE instead of Number.MIN_VALUE to compare:

0 > -Number.MAX_VALUE returns true.

1 Comment

-Number.MAX_VALUE is not equal to Number.MIN_VALUE. Furthermore, -Number.MAX_VALUE is a negative number, so you're saying 0 > [a negative number], which is always true.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.