A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/BigInt/asUintN below:

BigInt.asUintN() - JavaScript | MDN

BigInt.asUintN()

Baseline Widely available

BigInt.asUintN 静的メソッドは、 BigInt 値を符号なし整数に丸め、その値を返します。

試してみましょう
const U64_CEIL = 2n ** 64n;

console.log(BigInt.asUintN(64, U64_CEIL - 1n));
// 18446744073709551615n (2n ** 64n - 1n, the maximum non-wrapping value)
console.log(BigInt.asUintN(64, U64_CEIL));
// 0n (wraps to zero)
console.log(BigInt.asUintN(64, U64_CEIL + 1n));
// 1n
console.log(BigInt.asUintN(64, U64_CEIL * 2n));
// 0n (wraps on multiples)
console.log(BigInt.asUintN(64, U64_CEIL * -42n));
// 0n (also wraps on negative multiples)
構文
BigInt.asUintN(bits, bigint);
引数
bits

整数の大きさのために利用できるビット数。

bigint

指定されたビット数に収めるよう丸める整数値。

返値

bigint を 2^bits で割った剰余の値の符号なし整数です。

例 64ビットの範囲に収める

BigInt.asUintN() メソッドは、64ビットの数値の範囲に収めるのに便利です。

const max = 2n ** 64n - 1n;

BigInt.asUintN(64, max);
// ↪ 18446744073709551615n

BigInt.asUintN(64, max + 1n);
// ↪ 0n
// オーバーフローするのでゼロになる
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4