Number.POSITIVE_INFINITY
Number.POSITIVE_INFINITY 静态数据属性表示正 Infinity 值。
¥The Number.POSITIVE_INFINITY static data property represents the positive Infinity value.
Try it
值
描述
¥Description
Number.POSITIVE_INFINITY 值的行为与数学无穷大略有不同:
¥The Number.POSITIVE_INFINITY value behaves slightly differently than mathematical infinity:
- 任何正值(包括
POSITIVE_INFINITY)乘以POSITIVE_INFINITY就是POSITIVE_INFINITY。 - 任何负值(包括
NEGATIVE_INFINITY)乘以POSITIVE_INFINITY就是NEGATIVE_INFINITY。 - 任何正数除以
POSITIVE_INFINITY就是 正零(如 IEEE 754 中所定义)。 - 任何负数除以
POSITIVE_INFINITY就是 负零(如 IEEE 754.1 中所定义)。 - 零乘以
POSITIVE_INFINITY等于NaN。 NaN乘以POSITIVE_INFINITY为NaN。POSITIVE_INFINITY除以NEGATIVE_INFINITY之外的任意负值,得到NEGATIVE_INFINITY。POSITIVE_INFINITY除以除POSITIVE_INFINITY之外的任意正值,得到POSITIVE_INFINITY。POSITIVE_INFINITY除以NEGATIVE_INFINITY或POSITIVE_INFINITY,得到NaN。Number.POSITIVE_INFINITY > x对于除POSITIVE_INFINITY之外的任何数字 x 均成立。
你可以使用 Number.POSITIVE_INFINITY 属性来指示错误条件,如果成功则返回有限的数字。但请注意,在这种情况下,NaN 更合适。
¥You might use the Number.POSITIVE_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.
由于 POSITIVE_INFINITY 是 Number 的静态属性,因此你始终将其用作 Number.POSITIVE_INFINITY,而不是作为数字值的属性。
¥Because POSITIVE_INFINITY is a static property of Number, you always use it as Number.POSITIVE_INFINITY, rather than as a property of a number value.
示例
使用 POSITIVE_INFINITY
¥Using POSITIVE_INFINITY
在以下示例中,为变量 bigNumber 分配了一个大于最大值的值。当执行 if 语句时,bigNumber 的值为 Infinity,因此在继续之前将 bigNumber 设置为更易于管理的值。
¥In the following example, the variable bigNumber is assigned a value that is larger than the maximum value. When the if statement executes, bigNumber has the value Infinity, so bigNumber is set to a more manageable value before continuing.
let bigNumber = Number.MAX_VALUE * 2;
if (bigNumber === Number.POSITIVE_INFINITY) {
bigNumber = returnFinite();
}
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-number.positive_infinity |
浏览器兼容性
BCD tables only load in the browser