[英]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_VALUE
是5e-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。
`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.