「JavaScript/型付き配列」の版間の差分
削除された内容 追加された内容
→概要: リファクタリング |
→Uint8ClampedArray: https://tc39.es/ecma262/#sec-touint8clamp |
||
10 行
const b64 = new BigUint64Array(f64.buffer);
for (let i = 0, len = f64.length; i < len; i++)
console.log(`${(""+f64[i]).padStart(17," ")}: ${b64[i].toString(2).padStart(64,0)}`);
/*
0: 0000000000000000000000000000000000000000000000000000000000000000
1: 0011111111110000000000000000000000000000000000000000000000000000
*/
</source>
43 行
=== Uint8ClampedArray ===
オーバーフロー対策と丸め処理を施された8ビット符号なし整数のTypedArrayオブジェクト。
以下の変換規則に従います<ref>[https://tc39.es/ecma262/#sec-touint8clamp ECMA-262::7.1.12 ToUint8Clamp ( argument )]</ref>
* 数値に変換する
* NaN, +0, -0, Infinity 及び -Infinity は+0とする
* 0未満は0に丸める
* 255を超えると255に丸める
* [[w:端数処理#偶数への丸め(round_to_even)|最近接偶数丸め]]を行う
[[JavaScript/Canvas#imageData へのアクセスを使った高速化|Canva#imageData へのアクセスを使った高速化]]の節に、CanvasのimageDate.data(Uint8ClampedArrayオブジェクト)を直接操作して高速化をはかる例がある。
<source lang="js" line>
const ui8c = new Uint8ClampedArray(1);
[ NaN, +0, -0, -1, 256, 0.5, 0.5000000000001, 1.5, 1.5000000000001, ].forEach(x => console.log(ui8c[0] = x, ui8c[0]));
/*
NaN 0
0 0
-0 0
-1 0
256 255
0.5 0
0.5000000000001 1
*/
</source>
=== Int16Array ===
71 ⟶ 91行目:
=== BigUint64Array ===
64ビット符号なし整数のTypedArrayオブジェクト
== 脚注 ==
<references />
== 外部リンク ==
* [https://tc39.es/ecma262/#sec-typedarray-objects ECMA-262::23.2 TypedArray Objects]
[[Category:JavaScript|{{SUBPAGENAME}}]]
|