javascript - ECMAScript 中的 "positive"和 "negative"是什么意思? +0 和 -0

标签 javascript language-lawyer specifications

我正在阅读 ECMAScript 5.1 spec .它说:

The slice method takes two arguments, start and end [...]. If start is negative, it is treated as length+start where length is the length of the array. If end is negative, it is treated as length+end where length is the length of the array.

“负面”是什么意思?这是有道理的,就像在数学中一样,

  • 如果num > 0 , 然后 num这是积极的
  • 如果num < 0 , 然后 num是负面的。

但是+0呢?和 -0 ?在数学中有一个 0 ,既不是正数也不是负数。我的猜测是,在 ECMAScript 中,

  • +0 (又名正零)是积极的。
  • -0 (又名负零)是负的。

但我尝试使用 -0slice ,浏览器将其视为非负值。

然后,都是+0-0非正数和非负数,不管它们的名字是什么?

数字的正数或负数在哪里定义?我没有在 ECMAScript 规范中找到它的定义。定义是否继承自 IEEE 754?

最佳答案

你的困惑在这部分:

But what about +0 and -0? In math there is a single 0, which is not positive nor negative. My guess was that, in ECMAScript,

  • +0 (a.k.a. positive zero) is positive.
  • -0 (a.k.a. negative zero) is negative.

+0 不是正数; -0 不是负数。从概念上讲,它们都表示数字零 ,或者当发生下溢时,任何数量级太小而无法用有限可用位数表示的数字

+0-0 的决定更多地来自 IEEE 而不是 ECMA。

关于javascript - ECMAScript 中的 "positive"和 "negative"是什么意思? +0 和 -0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28703855/

相关文章:

javascript - 将 URL 发送到 Phantomjs?

javascript - 为什么一个细胞比其他细胞低?

javascript - Angular JS ui 路由器不显示模板(没有 js 控制台错误)

c++ - 这个带有空捕获列表的 lambda 如何能够引用到达范围名称?

specifications - SRS 文档与软件开发中的契约(Contract)签署相关 (b2b)

javascript - 谷歌地图航点不显示完整路径

c++ - void({}) 中的 {} 是什么?

javascript - 哪里指定文档中有一个 "onXYZ"?

specifications - 你们如何协作编写规范?

c++ - 为什么将 nullptr 作为 std::string 返回不是编译时错误?