mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Float16Array is a native typed-array kind with IEEE 754 binary16 storage. Stores round the number to nearest-even in one step from the double, as Node does, including overflow to Infinity, subnormals, -0 and NaN; reads widen exactly. The runtime converts with integer operations, so no target needs half-precision hardware or compiler-rt support. Construction, element reads and writes, ArrayBuffer views, fill, set, subarray, slice, both sort orders, constructor values and checked-dynamic storage work as for the other typed arrays. Math.f16round, DataView.prototype.getFloat16 and setFloat16, and util.types.isFloat16Array compile.
9 lines
316 B
TypeScript
9 lines
316 B
TypeScript
// Stored ArrayBuffers and DataViews lower, Float16 accessors included;
|
|
// detached accessor methods remain unsupported.
|
|
const buffer = new ArrayBuffer(16);
|
|
const view = new DataView(buffer);
|
|
view.setFloat16(0, 1.5);
|
|
console.log(view.getFloat16(0));
|
|
const getter = view.getFloat16;
|
|
// End of the diagnostic fixture.
|