gpt4 book ai didi

javascript - 同时具有正零和负零(+0,也写为0和-0)的目的是什么?

转载 作者:行者123 更新时间:2023-12-03 08:12:19 28 4
gpt4 key购买 nike

根据 ECMAScript 6.0 规范:

...there is both a positive zero and a negative zero. For brevity, these values are also referred to for expository purposes by the symbols +0 and -0, respectively. (Note that these two different zero Number values are produced by the program expressions +0 (or simply 0) and -0.)

因此,+0 和 -0 是不同的数值,但它们被视为相等。我已经检查过 -0 === +0 等于 true

我认为这只是数字在内存中存储方式的产物,并且这些值没有任何好处/目的/用途。

我说得对吗?

此外,维基百科指出:

while the two zero representations behave as equal under numeric comparisons, they yield different results in some operations

JavaScript中有这样的操作吗?

最佳答案

这是数字如何在内存中存储、表示和处理的问题,特别是对于浮点运算。

Signed zero is zero with an associated sign. In ordinary arithmetic, −0 = +0 = 0. However, in computing, some number representations allow for the existence of two zeros, often denoted by −0 (negative zero) and +0 (positive zero). This occurs in some signed number representations for integers, and in most floating point number representations. The number 0 is usually encoded as +0, but can be represented by either +0 or −0.

更多内容请参阅上一篇 answer

关于javascript - 同时具有正零和负零(+0,也写为0和-0)的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34088742/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com