aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/number/positive_infinity/index.html
blob: 8e572bf740e6bf63f7f2cd34ae2965b1b7d9a3e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: Number.POSITIVE_INFINITY
slug: Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY
translation_of: Web/JavaScript/Reference/Global_Objects/Number/POSITIVE_INFINITY
---
<div>{{JSRef("Global_Objects", "Number")}}</div>

<h2 id="概述">概述</h2>

<p><code><strong>Number.POSITIVE_INFINITY</strong></code> 属性表示正无穷大。</p>

<p>不必创建一个 {{jsxref("Global_Objects/Number", "Number")}} 实例,可使用 <code>Number.POSITIVE_INFINITY</code> 来访问该静态属性。</p>

<p>{{js_property_attributes(0,0,0)}}</p>

<h2 id="描述">描述</h2>

<p><code>Number.POSITIVE_INFINITY</code> 的值同全局对象 {{jsxref("Global_Objects/Infinity", "Infinity")}} 属性的值相同。</p>

<p>该值的表现同数学上的无穷大有点儿不同:</p>

<ul>
 <li>任何正值,包括 <code>POSITIVE_INFINITY</code>,乘以 <code>POSITIVE_INFINITY</code><code>POSITIVE_INFINITY</code></li>
 <li>任何负值,包括 <code>NEGATIVE_INFINITY</code>,乘以 <code>POSITIVE_INFINITY</code><code>NEGATIVE_INFINITY</code></li>
 <li>0 乘以 <code>POSITIVE_INFINITY</code> 为 NaN。</li>
 <li>NaN 乘以 <code>POSITIVE_INFINITY</code> 为 NaN。</li>
 <li><code>POSITIVE_INFINITY</code> 除以 <code>NEGATIVE_INFINITY</code> 以外的任何负值为 <code>NEGATIVE_INFINITY</code></li>
 <li><code>POSITIVE_INFINITY</code> 除以 <code>POSITIVE_INFINITY</code> 以外的任何正值为 <code>POSITIVE_INFINITY</code></li>
 <li><code>POSITIVE_INFINITY</code> 除以 <code>NEGATIVE_INFINITY</code><code>POSITIVE_INFINITY</code> 为 NaN。</li>
 <li>任何数除以 <code>POSITIVE_INFINITY</code> 为 0。</li>
</ul>

<p>You might use the <code>Number.POSITIVE_INFINITY</code> property to indicate an error condition that returns a finite number in case of success. Note, however, that {{jsxref("Global_Objects/isFinite", "isFinite")}} would be more appropriate in such a case.</p>

<h2 id="示例">示例</h2>

<p>下例中,赋值给变量 <code>bigNumber</code> 一个大于 JavaScript 中最大值的值。当 <code>if</code> 语句执行时,变量 <code>bigNumber</code> 值为 "<code>Infinity</code>", 因此在继续执行代码前,为变量 <code>bigNumber</code> 设置一个容易管理的值。</p>

<pre class="brush: js">var bigNumber = Number.MAX_VALUE * 2
if (bigNumber == Number.POSITIVE_INFINITY) {
 bigNumber = returnFinite();
}
</pre>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>ECMAScript 1st Edition. Implemented in JavaScript 1.1</td>
   <td>Standard</td>
   <td>Initial definition.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.7.3.6', 'Number.POSITIVE_INFINITY')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-number.positive_infinity', 'Number.POSITIVE_INFINITY')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性">浏览器兼容性</h2>

{{Compat}}

<h2 id="See_also">相关链接</h2>

<ul>
 <li>{{jsxref("Number.NEGATIVE_INFINITY")}}</li>
 <li>{{jsxref("Global_Objects/Infinity", "Infinity")}}</li>
 <li>{{jsxref("Global_Objects/isFinite", "isFinite")}}</li>
</ul>