--- title: BigInt.asIntN() slug: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN tags: - BigInt - JavaScript - Method - Reference - asIntN - メソッド translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN ---
BigInt.asIntN
静的メソッドは、 BigInt 値を -2width-1 から 2width-1-1 までの間の符号付き整数に丸めるために使われます。
BigInt.asIntN(width, bigint);
width
bigint
bigint
を 2width
で割った剰余の値の符号付き整数です。
BigInt.asIntN()
メソッドは、64ビットの数値の範囲に収めるのに便利です。
const max = 2n ** (64n - 1n) - 1n; BigInt.asIntN(64, max); // ↪ 9223372036854775807n BigInt.asIntN(64, max + 1n); // ↪ -9223372036854775807n // オーバーフローするので負数になる
仕様書 |
---|
{{SpecName('ESDraft', '#sec-bigint.asintn', 'BigInt.asIntN()')}} |
{{Compat("javascript.builtins.BigInt.asIntN")}}