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?
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.
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.Number.MIN_VALUE is equivalent to 5e-324 , which is greater than 0.
-324. I taught high schoolers who thought that 3 ** -2 === -9.Since Number.MIN_VALUE = 5e-324 = 5 x 10^-324 and it's greater than 0(a little bit greater).
Read more here.
Number.MIN_SAFE_INTEGER is undefined in Node.js 0.10.x.e notation. A positive number raised to a negative exponent is still positive. I taught high schoolers who thought that 3 ** -2 === -9.Use -Number.MAX_VALUE instead of Number.MIN_VALUE to compare:
0 > -Number.MAX_VALUE returns true.
-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.
Number.MIN_SAFE_INTEGERNumber.MIN_SAFE_INTEGERisundefinedin Node.js 0.10.x.