为什么 1/0=Infinity 和 1/-0=-Infinity

Why is 1/0=Infinity and 1/-0=-Infinity

为什么会这样:

1 === 1;// true
0 === -0;// true
1/0 === 1/-0;// false

原因:

1/0=Infinite;
1/-0=-Infinite;

问题:

为什么不是 1/0 或 1/-0 未定义NaN?

It can't be Infinity or -Infinity, because of 0 is equal to -0, so 1/0 is equal to 1/-0 I should say, but why it isn't? And why it isn't Undefined (what my calculator says) or NaN.

这是因为IEEE 754 specifications是这样定义的。

然而,这是有原因的:affinely extended real number system extends the real numbers with the two infinities, which gives some more room for calculating with limits。因此,对于此扩展,除以零不是 undefinedNaN.

考虑以下对于正 x 成立:

limx→0(x) = limx→0(-x)

然而下面的不正确 x:

limx→0(1/x) = limx→0(1/-x)

请注意上述与极限符号的比较如何映射到您列出的比较:

0 === -0;// true
1/0 === 1/-0;// false

其次,除法始终保持以下不变性:当且仅当恰好一个操作数为负时,结果为负。

这两个考虑因素都为 IEEE 754 中的原因提供了一些可信度:

1/0 === Infinity
1/-0 === -Infinity