A proposal to add float16 (aka half-precision or binary16) TypedArrays to JavaScript.
Authors: Kevin Gibbons
Champions: Leo Balter
This proposal is at Stage 1 of The TC39 Process.
Spec text is available here.
- Explicit request from the Color on the Web CG, for their use case with float-backed canvases.
- Useful for GPU operations, where full precision often isn't necessary and memory constraints are serious.
- WebGPU supports float16. It exposes/consumes raw ArrayBuffers. When those contain 32-bit floats, the pattern is to wrap the buffer in
new Float32Array(...)
; that doesn't work when they contain 16-bit floats. - Increasingly relevant with new tools like Stable Diffusion, where full-precision representations don't fit in VRAM on many machines.
- WebGPU supports float16. It exposes/consumes raw ArrayBuffers. When those contain 32-bit floats, the pattern is to wrap the buffer in
- Faking it in userland has serious performance costs.
This would add a new kind of TypedArray, Float16Array
, to complement the existing Float32Array
and Float64Array
. It would also add two new methods on DataView
for reading and setting float16 values, as getFloat16
and setFloat16
, to complement the existing similar methods for working with full and double precision floats.