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/Atomics/or below:

Atomics.or() - JavaScript | MDN

Atomics.or()

Baseline Widely available

Atomics.or() は静的メソッドで、配列内の指定した位置の値に指定した値でビット単位の OR を計算し、その位置にあった古い値を返します。これは不可分操作で、修正された値が書き戻されるまで、他の書き込みが起こらないことを保証します。

試してみましょう
// バイト単位でサイズを指定して SharedArrayBuffer を作成
const buffer = new SharedArrayBuffer(16);
const uint8 = new Uint8Array(buffer);
uint8[0] = 5;

// 5 (0101) OR 2 (0010) = 7 (0111)
console.log(Atomics.or(uint8, 0, 2));
// 予想される結果: 5

console.log(Atomics.load(uint8, 0));
// 予想される結果: 7
構文
Atomics.or(typedArray, index, value)
引数
typedArray

整数の型付き配列です。 Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, BigUint64Array の何れかです。

index

typedArray でビット単位の OR を計算する位置です。

value

ビット単位の OR を取る数値です。

返値

指定された位置 (typedArray[index]) にあった古い値です。

例外
TypeError

typedArray が許可された整数型のいずれでもない場合に発生します。

RangeError

index が typedArray の範囲を超えている場合に発生します。

解説

ビット単位の OR 操作は、 a と b のどちらかが 1 であった場合に 1 を生成します。 OR 操作の真理値表を示します。

a b a | b 0 0 0 0 1 1 1 0 1 1 1 1

例えば、ビット単位の OR を 5 | 1 で行うと、結果は 0101 すなわち 10 進数で 5 となります。

5  0101
1  0001
   ----
5  0101
例 or の使用
const sab = new SharedArrayBuffer(1024);
const ta = new Uint8Array(sab);
ta[0] = 2;

Atomics.or(ta, 0, 1); // returns 2, the old value
Atomics.load(ta, 0); // 3
仕様書 ブラウザーの互換性 関連情報

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