我正在阅读 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
(又名负零)是负的。
但我尝试使用 -0
与 slice
,浏览器将其视为非负值。
然后,都是+0
和 -0
非正数和非负数,不管它们的名字是什么?
数字的正数或负数在哪里定义?我没有在 ECMAScript 规范中找到它的定义。定义是否继承自 IEEE 754?
最佳答案
你的困惑在这部分:
But what about
+0
and-0
? In math there is a single0
, 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/