This proposal adds a new kind of TypedArray. TypedArrays are specified in a slightly different way from the rest of the standard library, so the specification for this proposal consists of a surprisingly small change.
The abstract operation RawBytesToNumeric takes arguments type (a TypedArray element type), rawBytes (a List of byte values), and isLittleEndian (a Boolean) and returns a Number or a BigInt.
The algorithm below is modified by the addition of a case for Float16.
Let elementSize be the Element Size value specified in Table 1 for Element Type type.
If isLittleEndian is false, reverse the order of the elements of rawBytes.
If type is Float16, then
Let value be the byte elements of rawBytes concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2019 binary16 value.
If value is an IEEE 754-2019 binary16 NaN value, return the NaN Number value.
Return the Number value that corresponds to value.
If type is Float32, then
Let value be the byte elements of rawBytes concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2019 binary32 value.
If value is an IEEE 754-2019 binary32 NaN value, return the NaN Number value.
Return the Number value that corresponds to value.
If type is Float64, then
Let value be the byte elements of rawBytes concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2019 binary64 value.
If value is an IEEE 754-2019 binary64 NaN value, return the NaN Number value.
Return the Number value that corresponds to value.
Let intValue be the byte elements of rawBytes concatenated and interpreted as a bit string encoding of an unsigned little-endian binary number.
Else,
Let intValue be the byte elements of rawBytes concatenated and interpreted as a bit string encoding of a binary little-endian two's complement number of bit length elementSize × 8.
If IsBigIntElementType(type) is true, return the BigInt value that corresponds to intValue.
Otherwise, return the Number value that corresponds to intValue.
The abstract operation NumericToRawBytes takes arguments type (a TypedArray element type), value (a Number or a BigInt), and isLittleEndian (a Boolean) and returns a List of byte values.
The algorithm below is modified by the addition of a case for Float16.
If type is Float16, then
Let rawBytes be a List whose elements are the 2 bytes that are the result of converting value to IEEE 754-2019 binary16 format using roundTiesToEven mode. The bytes are arranged in little endian order. If value is NaN, rawBytes may be set to any implementation chosen IEEE 754-2019 binary16 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.
Else if type is Float32, then
Let rawBytes be a List whose elements are the 4 bytes that are the result of converting value to IEEE 754-2019 binary32 format using roundTiesToEven mode. The bytes are arranged in little endian order. If value is NaN, rawBytes may be set to any implementation chosen IEEE 754-2019 binary32 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.
Else if type is Float64, then
Let rawBytes be a List whose elements are the 8 bytes that are the IEEE 754-2019 binary64 format encoding of value. The bytes are arranged in little endian order. If value is NaN, rawBytes may be set to any implementation chosen IEEE 754-2019 binary64 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.
Else,
Let n be the Element Size value specified in Table 1 for Element Type type.
Let convOp be the abstract operation named in the Conversion Operation column in Table 1 for Element Type type.