Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是什么导致javascript中的超小数字被识别为不同的布尔值?_Javascript_Google Chrome_Math - Fatal编程技术网

是什么导致javascript中的超小数字被识别为不同的布尔值?

是什么导致javascript中的超小数字被识别为不同的布尔值?,javascript,google-chrome,math,Javascript,Google Chrome,Math,为什么这些非常小的数字有不同的输出 在一个数字不再为真变为假之前,它能有多小的决定因素是什么 一个数字(顶部)长327个字符(小数点后324个零),输出为true: 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

为什么这些非常小的数字有不同的输出

在一个数字不再为真变为假之前,它能有多小的决定因素是什么

一个数字(顶部)长327个字符(小数点后324个零),输出为
true
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

另一个(底部)长度为326个字符(小数点后323个零),输出为
false
0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

经进一步调查:


为什么这会使一个数字变为或变为一个数字?

表示数字的位已经用完了

javascript中的数字是(在C中键入“double”)。双精度编码如下:

 ┌─┬────────────┬──────────────────────────────────────┐
 │ │ bits 52-62 │           bits 0 - 51                │
 └─┴────────────┴──────────────────────────────────────┘
  ^     ^                  ^
  │     │                  └── number (also called mantissa)
  │     └────── exponent
  └── sign bit 
解释编码的公式为:

            (exponent - 1023)
number x  2
或者在代码中,它看起来像:

number * Math.pow(2, exponent - 1023)
因此,javascript(或C/Java/C#等)可以表示的最小数字是:

1 x 2⁻¹⁰²²   // exponent 0 has special meaning so the smallest exponent is 1
这实际上是
5x10⁻³²⁴。即:

0.0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0005

任何较小的数字都无法表示,因此会四舍五入到最接近的可表示数字。

表示数字的位刚刚用完

javascript中的数字是(在C中键入“double”)。双精度编码如下:

 ┌─┬────────────┬──────────────────────────────────────┐
 │ │ bits 52-62 │           bits 0 - 51                │
 └─┴────────────┴──────────────────────────────────────┘
  ^     ^                  ^
  │     │                  └── number (also called mantissa)
  │     └────── exponent
  └── sign bit 
解释编码的公式为:

            (exponent - 1023)
number x  2
或者在代码中,它看起来像:

number * Math.pow(2, exponent - 1023)
因此,javascript(或C/Java/C#等)可以表示的最小数字是:

1 x 2⁻¹⁰²²   // exponent 0 has special meaning so the smallest exponent is 1
这实际上是
5x10⁻³²⁴。即:

0.0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0000000000 0000000000 0000000000
  0000000000 0000000000 0005

任何较小的数字都无法表示,因此会四舍五入到最接近的可表示数字。

其中一个是小的非零数字,另一个只是0(以比通常更长的格式表示),它不会被打断,它比任何其他JavaScript数字都更接近0,JavaScript总是使用最接近的数字。看看其中一个是一个小的非零数字,另一个只是0(以比通常更长的格式表示),它没有被破坏,它比任何其他JavaScript数字都更接近0,JavaScript总是使用最接近的数字。请查看小于
number.MIN\u值但大于
number.MIN\u值的任何数字。MIN\u值/2
number.MIN\u值
。任何小于或等于
数字的值。最小值/2
为零。@Paulpro啊,是的。忘记了舍入任何小于
Number.MIN\u值但大于
Number的值。MIN\u值/2
Number.MIN\u值
。任何小于或等于
数字的值。最小值/2
为零。@Paulpro啊,是的。忘了四舍五入