Why is 0 less than Number.MIN_VALUE in JavaScript?

前端 未结 4 1671
孤独总比滥情好
孤独总比滥情好 2021-01-03 20:24

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

0 < Number.MIN_VALUE

To my surprise, this returns true. Why is that? And: Ho

相关标签:
4条回答
  • 2021-01-03 20:41

    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.

    0 讨论(0)
  • 2021-01-03 20:47

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

    0 讨论(0)
  • 2021-01-03 20:58

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

    0 > -Number.MAX_VALUE returns true.

    0 讨论(0)
  • 2021-01-03 21:02

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

    0 讨论(0)
提交回复
热议问题