demo · v135
Float16Array round-trip
Chrome 135 ships Float16Array — 2 bytes per number, IEEE 754 binary16. Type a value, see what survives the round-trip, and compare bytes against Float32 / Float64.
Float16Array: ?
Float16Array (Chrome 135+)
—
— bytes
Float32Array
—
— bytes
Float64Array
—
— bytes
the code
const a = new Float16Array([0.1, 0.2, 0.3]);
console.log(a[0]); // 0.0999755859375
console.log(a.byteLength / a.length); // 2
const dv = new DataView(a.buffer);
console.log(dv.getUint16(0, true).toString(16)); // raw bits
see also
- Float16Array — feature index
- ChromeStatus entry
- TC39 proposal