BigInt.asIntN
static method is used to wrap a BigInt value to a signed integer between -2
width-1
and 2
width-1
-1.
BigInt.asIntN(width, bigint);
width
The amount of bits available for the integer size.
bigint
The integer to clamp to fit into the supplied bits.
值
bigint
modulo 2
width
as a signed integer.
BigInt.asIntN()
method can be useful to stay in the range of 64-bit arithmetic.
const max = 2n ** (64n - 1n) - 1n; BigInt.asIntN(64, max); // ↪ 9223372036854775807n BigInt.asIntN(64, max + 1n); // ↪ -9223372036854775807n // negative because of overflow
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'BigInt.asIntN()' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
asIntN
|
Chrome 67 | Edge 79 | Firefox 68 | IE No | Opera 54 | Safari No | WebView Android 67 | Chrome Android 67 | Firefox Android 68 | Opera Android 48 | Safari iOS No | Samsung Internet Android 9.0 | nodejs 10.4.0 |
完整支持
不支持
BigInt
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()