gpt4 book ai didi

javascript - javascript有负零的概念吗

转载 作者:数据小太阳 更新时间:2023-10-29 05:16:48 25 4
gpt4 key购买 nike

考虑以下内容

var l = console.log.bind(console);
l(-0); // 0
l(0); // 0
l(0 === -0); // true
l(0 == -0); // true
l(1 / 0); // Infinity
l(1 / -0); // -Infinity
  • 为什么负零等于零?
  • 鉴于它是平等的,为什么它的行为不同?

奖励问题:

  • 0/-0 组合是相同对象表现不同的唯一组合吗?

我知道 NaN/NaN 是一个组合,其中不相等的对象表现相同。

最佳答案

Why is negative zero equal to zero ?

因为 IEEE 754 demands it .

Is the 0/-0 combination the only combination where equal objects behave differently?

我相信。在 Javascript 中,只有数字有特殊的 === 算法,而 0、-0、NaN 是唯一的特殊情况 (ECMA-262 §11.9.6)。

关于javascript - javascript有负零的概念吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6807619/

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