简体   繁体   English

为什么 JavaScript 中的 Number.MIN_VALUE 小于 0?

[英]Why is 0 less than Number.MIN_VALUE in JavaScript?

Using Node.js, I'm evaluating the expression:使用 Node.js,我正在评估表达式:

0 < Number.MIN_VALUE

To my surprise, this returns true .令我惊讶的是,这返回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 , ie the smallest positive number that can be represented within float precision, ie that's as close as you can get to zero. Number.MIN_VALUE5e-324 ,即可以在float精度内表示的最小正数,即尽可能接近零。 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尽管从严格意义上讲它并不是真正的数字。

Number.MIN_VALUE等于5e-324,大于0。

Since Number.MIN_VALUE = 5e-324 = 5 x 10^-324 and it's greater than 0 (a little bit greater). 由于Number.MIN_VALUE = 5e-324 = 5 x 10^-324并且它大于 0 (稍微大一些)。
Read more here . here阅读更多。

`Number.MIN_VALUE` is equal to 5e-324 or 5*(10^-324);

it's math.这是数学。 any positive number is greater than zero.任何正数都大于零。

Use -Number.MAX_VALUE instead of Number.MIN_VALUE to compare: 使用-Number.MAX_VALUE而不是Number.MIN_VALUE进行比较:

0 > -Number.MAX_VALUE returns true . 0 > -Number.MAX_VALUE返回true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM