mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-10 07:54:06 +08:00
116 lines
5.8 KiB
HTML
116 lines
5.8 KiB
HTML
<article id="wikiArticle">
|
||
<div></div>
|
||
<p><strong><code>Number.MAX_SAFE_INTEGER</code></strong> 常量表示在 JavaScript 中最大的安全整数(maxinum safe integer)(<code>2<sup>53</sup> - 1)。</code></p>
|
||
<div><table class="standard-table">
|
||
<thead>
|
||
<tr>
|
||
<th class="header" colspan="2"><code>Number.MAX_SAFE_INTEGER</code> 属性的属性特性:</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>writable</td>
|
||
<td>false</td>
|
||
</tr>
|
||
<tr>
|
||
<td>enumerable</td>
|
||
<td>false</td>
|
||
</tr>
|
||
<tr>
|
||
<td>configurable</td>
|
||
<td>false</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<h2 id="描述">描述</h2>
|
||
<p><code>MAX_SAFE_INTEGER 是一个值为 9007199254740991的常量。因为Javascript的数字存储使用了</code><a class="external" href="http://en.wikipedia.org/wiki/IEEE_floating_point" rel="noopener">IEEE 754</a>中规定的<a class="external" href="https://zh.wikipedia.org/zh-cn/%E9%9B%99%E7%B2%BE%E5%BA%A6%E6%B5%AE%E9%BB%9E%E6%95%B8" rel="noopener">双精度浮点数</a>数据类型,而这一数据类型能够安全存储 <code>-(2<sup>53</sup> - 1)</code> 到 <code>2<sup>53</sup> - 1 之间的数值(包含边界值)。</code></p>
|
||
<p>这里安全存储的意思是指能够准确区分两个不相同的值,例如 <code>Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2 将得到 true的结果,而这在数学上是错误的,参考</code><a href="Reference/Global_Objects/Number/isSafeInteger" title="Number.isSafeInteger() 方法用来判断传入的参数值是否是一个“安全整数”(safe integer)。一个安全整数是一个符合下面条件的整数:"><code>Number.isSafeInteger()</code></a>获取更多信息.</p>
|
||
<p>由于 <code>MAX_SAFE_INTEGER 是</code><a href="Reference/Global_Objects/Number" title="JavaScript 的 Number 对象是经过封装的能让你处理数字值的对象。Number 对象由 Number() 构造器创建。"><code>Number</code></a>的一个<code>静态属性,所以你不用自己动手为</code><a href="Reference/Global_Objects/Number" title="JavaScript 的 Number 对象是经过封装的能让你处理数字值的对象。Number 对象由 Number() 构造器创建。"><code>Number</code></a>对象创建<code>Number.MAX_SAFE_INTEGER</code>这一属性,就可以直接使用它。</p>
|
||
<h2 id="示例">示例</h2>
|
||
<pre><code class="language-javascript">Number.MAX_SAFE_INTEGER // 9007199254740991
|
||
Math.pow(2, 53) - 1 // 9007199254740991
|
||
</code></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><a class="external" href="https://www.ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer" hreflang="en" lang="en" rel="noopener">ECMAScript 2015 (6th Edition, ECMA-262)<br/><small lang="zh-CN">Number.MAX_SAFE_INTEGER</small></a></td>
|
||
<td><span class="spec-Standard">Standard</span></td>
|
||
<td>首次定义</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a class="external" href="https://tc39.github.io/ecma262/#sec-number.max_safe_integer" hreflang="en" lang="en" rel="noopener">ECMAScript Latest Draft (ECMA-262)<br/><small lang="zh-CN">Number.MAX_SAFE_INTEGER</small></a></td>
|
||
<td><span class="spec-Draft">Draft</span></td>
|
||
<td> </td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<h2 id="浏览器兼容性">浏览器兼容性</h2>
|
||
<div><div class="blockIndicator warning"><strong><a class="external" href="https://github.com/mdn/browser-compat-data" rel="noopener">We're converting our compatibility data into a machine-readable JSON format</a></strong>.
|
||
This compatibility table still uses the old format,
|
||
because we haven't yet converted the data it contains.
|
||
<strong><a class="new" href="/zh-CN/docs/MDN/Contribute/Structures/Compatibility_tables" rel="nofollow">Find out how you can help!</a></strong></div>
|
||
<div class="htab">
|
||
<a id="AutoCompatibilityTable" name="AutoCompatibilityTable"></a>
|
||
<ul>
|
||
<li class="selected"><a>Desktop</a></li>
|
||
<li><a>Mobile</a></li>
|
||
</ul>
|
||
</div></div>
|
||
<div id="compat-desktop">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Chrome</th>
|
||
<th>Firefox (Gecko)</th>
|
||
<th>Internet Explorer</th>
|
||
<th>Opera</th>
|
||
<th>Safari</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td>34</td>
|
||
<td><a href="/en-US/Firefox/Releases/31" title="Released on 2014-07-22.">31</a> (31)</td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
||
<td>9.0.2</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div id="compat-mobile">
|
||
<table class="compat-table">
|
||
<tbody>
|
||
<tr>
|
||
<th>Feature</th>
|
||
<th>Android</th>
|
||
<th>Chrome for Android</th>
|
||
<th>Firefox Mobile (Gecko)</th>
|
||
<th>IE Mobile</th>
|
||
<th>Opera Mobile</th>
|
||
<th>Safari Mobile</th>
|
||
</tr>
|
||
<tr>
|
||
<td>Basic support</td>
|
||
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
||
<td><span style="color: #888;" title="Please update this with the earliest version of support.">(Yes)</span></td>
|
||
<td>32.0 (32)</td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
<td><span style="color: #f00;">未实现</span></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<h2 id="相关链接">相关链接</h2>
|
||
<ul>
|
||
<li><a href="Reference/Global_Objects/Number/MIN_SAFE_INTEGER" title="Number.MIN_SAFE_INTEGER 代表在 JavaScript中最小的安全的integer型数字 (-(253 - 1))."><code>Number.MIN_SAFE_INTEGER</code></a></li>
|
||
<li><a href="Reference/Global_Objects/Number/isSafeInteger" title="Number.isSafeInteger() 方法用来判断传入的参数值是否是一个“安全整数”(safe integer)。一个安全整数是一个符合下面条件的整数:"><code>Number.isSafeInteger()</code></a></li>
|
||
</ul>
|
||
</article> |