Number.NEGATIVE_INFINITY

Number.NEGATIVE_INFINITY 静态数据属性表示负无穷大值。

¥The Number.NEGATIVE_INFINITY static data property represents the negative Infinity value.

Try it

¥Value

与全局 Infinity 属性的负值相同。

¥The same as the negative value of the global Infinity property.

Property attributes of Number.NEGATIVE_INFINITY
Writable no
Enumerable no
Configurable no

描述

¥Description

Number.NEGATIVE_INFINITY 值的行为与数学无穷大略有不同:

¥The Number.NEGATIVE_INFINITY value behaves slightly differently than mathematical infinity:

  • 任何正值(包括 POSITIVE_INFINITY)乘以 NEGATIVE_INFINITY 就是 NEGATIVE_INFINITY
  • 任何负值(包括 NEGATIVE_INFINITY)乘以 NEGATIVE_INFINITY 就是 POSITIVE_INFINITY
  • 任何正值除以 NEGATIVE_INFINITY 就是 负零(如 IEEE 754 中所定义)。
  • 任何负值除以 NEGATIVE_INFINITY 就是 正零(如 IEEE 754 中所定义)。
  • 零乘以 NEGATIVE_INFINITY 等于 NaN
  • NaN 乘以 NEGATIVE_INFINITYNaN
  • NEGATIVE_INFINITY 除以 NEGATIVE_INFINITY 之外的任意负值,得到 POSITIVE_INFINITY
  • NEGATIVE_INFINITY 除以除 POSITIVE_INFINITY 之外的任意正值,得到 NEGATIVE_INFINITY
  • NEGATIVE_INFINITY 除以 NEGATIVE_INFINITYPOSITIVE_INFINITY,得到 NaN
  • x > Number.NEGATIVE_INFINITY 对于除 NEGATIVE_INFINITY 之外的任何数字 x 均成立。

你可以使用 Number.NEGATIVE_INFINITY 属性来指示错误条件,如果成功则返回有限的数字。但请注意,在这种情况下,NaN 更合适。

¥You might use the Number.NEGATIVE_INFINITY property to indicate an error condition that returns a finite number in case of success. Note, however, that NaN would be more appropriate in such a case.

由于 NEGATIVE_INFINITYNumber 的静态属性,因此你始终将其用作 Number.NEGATIVE_INFINITY,而不是作为数字值的属性。

¥Because NEGATIVE_INFINITY is a static property of Number, you always use it as Number.NEGATIVE_INFINITY, rather than as a property of a number value.

示例

¥Examples

使用 NEGATIVE_INFINITY

¥Using NEGATIVE_INFINITY

在以下示例中,为变量 smallNumber 分配了一个小于最小值的值。当执行 if 语句时,smallNumber 的值为 -Infinity,因此在继续之前将 smallNumber 设置为更易于管理的值。

¥In the following example, the variable smallNumber is assigned a value that is smaller than the minimum value. When the if statement executes, smallNumber has the value -Infinity, so smallNumber is set to a more manageable value before continuing.

js
let smallNumber = -Number.MAX_VALUE * 2;

if (smallNumber === Number.NEGATIVE_INFINITY) {
  smallNumber = returnFinite();
}

规范

Specification
ECMAScript Language Specification
# sec-number.negative_infinity

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看