--- title: BigInt.asIntN() slug: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN translation_of: Web/JavaScript/Reference/Global_Objects/BigInt/asIntN ---
BigInt.asIntN
静态方法将 BigInt
值转换为一个 -2^(width-1)
与 2^(width-1)-1
之间的有符号整数。
BigInt.asIntN(width, bigint);
width
bigint
bigint
模(modulo) 2^width
作为有符号整数的值。
BigInt.asIntN()
方法对于保持在64位(64-bit)算数范围内非常有用。
const max = 2n ** (64n - 1n) - 1n; BigInt.asIntN(64, max); // ↪ 9223372036854775807n BigInt.asIntN(64, max + 1n); // ↪ -9223372036854775808n // negative because of overflow
Specification | Status |
---|---|
{{SpecName('ESDraft', '#sec-bigint.asintn', 'BigInt.asIntN()')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.BigInt.asIntN")}}