aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/global_objects/bigint/asintn/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/bigint/asintn/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/global_objects/bigint/asintn/index.html73
1 files changed, 73 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/bigint/asintn/index.html b/files/zh-cn/web/javascript/reference/global_objects/bigint/asintn/index.html
new file mode 100644
index 0000000000..cab753a464
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/global_objects/bigint/asintn/index.html
@@ -0,0 +1,73 @@
+---
+title: BigInt.asIntN()
+slug: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN
+translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN
+---
+<div>{{JSRef}}</div>
+
+<p><strong><code>BigInt.asIntN</code></strong> 静态方法将 <code>BigInt</code> 值转换为一个 -<code>2<sup>width-1</sup></code> 与 <code>2<sup>width-1</sup>-1</code> 之间的有符号整数。</p>
+
+<div>{{EmbedInteractiveExample("pages/js/bigint-asintn.html")}}</div>
+
+
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">BigInt.asIntN(<var>width</var>, <var>bigint</var>);</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt><code>width</code></dt>
+ <dd>可存储整数的位数。</dd>
+ <dt><code>bigint</code></dt>
+ <dd>要存储在指定位数上的整数。</dd>
+</dl>
+
+<h3 id="返回值">返回值</h3>
+
+<p><code>bigint</code> 模(modulo) 2<sup><code>width</code></sup> 作为有符号整数的值。</p>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="保持在64位范围内">保持在64位范围内</h3>
+
+<p><code>BigInt.asIntN()</code> 方法对于保持在64位(64-bit)算数范围内非常有用。</p>
+
+<pre class="brush: js">const max = 2n ** (64n - 1n) - 1n;
+
+BigInt.asIntN(64, max);
+// ↪ 9223372036854775807n
+
+BigInt.asIntN(64, max + 1n);
+// ↪ -9223372036854775808n
+// negative because of overflow
+</pre>
+
+<h2 id="标准">标准</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-bigint.asintn', 'BigInt.asIntN()')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器支持">浏览器支持</h2>
+
+
+
+<p>{{Compat("javascript.builtins.BigInt.asIntN")}}</p>
+
+<h2 id="请参阅">请参阅</h2>
+
+<ul>
+ <li>{{JSxRef("BigInt")}}</li>
+ <li>{{JSxRef("BigInt.asUintN()")}}</li>
+</ul>