在 JavaScript 中,整数如何在存储布局中表示?
JavaScript 为所有数字文字提供 64 位浮点数,并且存储布局和范围在 ITEE 下进行管理754..
另一方面,我了解到浮点数的范围为 ± ~10^-323.3 到 ~10^308.3 以及尽可能可靠的精度。整数的范围是-2^53 - 2^53,并且精度可靠。
ITEE 754 解释了浮点数的行为,但我对 JS 中的整数感到困惑。 64位数据格式生成的精度范围是怎样的?
[已解决] 该值存储在小数位置。 1 为 (1+0)*2^0
,2 为 (1 + 0) * 2^1
,3 为 (1 + 2^-1 )*2^1
... -2^53 到 2^53 之间的任何数字都可以精确表示。 由于所有分数都有前导 1,因此范围为 -2^53 到 2^53
JavaScript comes with 64bit float numbers for all numeric literals, and the storage layout and range is regulated under ITEE 754.
On the other hand, I learned that the float has a range of ± ~10^-323.3 to ~10^308.3 and an as-reliable-as-possible precision. Integer has a range of -2^53 - 2^53 and a reliable precision.
ITEE 754 explains the behavior of float numbers but I get confused about the integer in JS. How is the range of precision generated from the 64bit data format?
[Solved]
The value is stored in the fraction position.1 is (1+0)*2^0
, 2 is (1 + 0) * 2^1
, 3 is (1 + 2^-1)*2^1
... Any number between -2^53 and 2^53 could be expressed precisely.
As there is a leading 1 for all fraction, the range is -2^53 to 2^53
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上它是-2^52 到2^52。发生的情况是整数实际上以浮点格式存储。在 yout URL 中,您可以看到从 64 位到 52 位用于分数。这就是数字实际存储的地方。
Actually it is -2^52 to 2^52. What happens is that integer is actually stored in floating point format. At yout URL you can see that from 64 bits 52 bits are used for fraction. That is where number is actually stored.
尽可能可靠意味着精确的 2^52 范围。虽然您可以表示大于该数字的数字,但在此之后您将开始跳过一些整数。
As reliable as possible means precisely the 2^52 range. While you can represent numbers larger than that you start skiping some integers after this point.
[自己解决] 该值存储在小数位置。 1 为 (1+0)*2^0、2 为 (1 + 0) * 2^1、3 为 (1 + 2^-1)*2^1...-2^53 和 2 之间的任何数字^53可以准确表达。由于所有分数都有前导 1,因此范围为 -2^53 到 2^53
[Solved myself] The value is stored in the fraction position. 1 is (1+0)*2^0, 2 is (1 + 0) * 2^1, 3 is (1 + 2^-1)*2^1... Any number between -2^53 and 2^53 could be expressed precisely. As there is a leading 1 for all fraction, the range is -2^53 to 2^53