JavaScript中64位的65位数字是如何存储的?

How is 65 bits number stored in 64 bits in JavaScript?

在 Douglas Crockford 的“JavaScript 工作原理”一书的“数字工作原理”一章中提到 JavaScript 中的数字由 1 个有符号位、11 个指数组成位和 53 个有效位。这总共是 65 位,一些巧妙的编码 允许将这 65 位存储在 64 位中,我们将其理解为 64 位浮点数。

更进一步,有效数字存储为 0.5 <= significand < 1.0

范围内的二进制小数

In that form, the most significant bit is always a 1. Since that bit is always a 1, it does not need to be stored in the number. This yields a bonus bit.

不明白

  1. 最高有效位(符号位)如何始终为 1?
  2. 如果不存储符号位,它如何区分正数和负数?

请帮助我理解这个概念或指导我朝着可以帮助我的方向发展。

double-precision floating point format Crockford 引用的分数(尾数)部分有 52 位,而不是 53 位:

维基百科文章提到了“有效精度”。他们是这样解释的:

The format is written with the significand having an implicit integer bit of value 1. With the 52 bits of the fraction (F) significand appearing in the memory format, the total precision is therefore 53 bits (approximately 16 decimal digits, 53 log10(2) ≈ 15.955).

这一定是 Crockford 所说的“巧妙编码”。从程序员的角度来看,这并不重要,除非你正在做一些奇特的事情,比如位旋转或整数转换。这就是Crockford没有进一步解释的原因。

相关: Is it 52 or 53 bits of floating point precision?