Why is 0 less than Number.MIN_VALUE in JavaScript?

ぐ巨炮叔叔 提交于 2019-12-19 12:24:34

问题


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?


回答1:


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.




回答2:


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




回答3:


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




回答4:


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

0 > -Number.MAX_VALUE returns true.



来源:https://stackoverflow.com/questions/26614728/why-is-0-less-than-number-min-value-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!