Skip to content

Commit d430ace

Browse files
bakkotljharb
authored andcommitted
Normative: add Float16Array and Math.f16round (#3532)
1 parent f2bad00 commit d430ace

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

spec.html

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,17 @@ <h1>Well-Known Intrinsic Objects</h1>
35393539
The FinalizationRegistry constructor (<emu-xref href="#sec-finalization-registry-constructor"></emu-xref>)
35403540
</td>
35413541
</tr>
3542+
<tr>
3543+
<td>
3544+
%Float16Array%
3545+
</td>
3546+
<td>
3547+
`Float16Array`
3548+
</td>
3549+
<td>
3550+
The Float16Array constructor (<emu-xref href="#sec-typedarray-objects"></emu-xref>)
3551+
</td>
3552+
</tr>
35423553
<tr>
35433554
<td>
35443555
%Float32Array%
@@ -30109,6 +30120,11 @@ <h1>FinalizationRegistry ( . . . )</h1>
3010930120
<p>See <emu-xref href="#sec-finalization-registry-constructor"></emu-xref>.</p>
3011030121
</emu-clause>
3011130122

30123+
<emu-clause id="sec-float16array">
30124+
<h1>Float16Array ( . . . )</h1>
30125+
<p>See <emu-xref href="#sec-typedarray-constructors"></emu-xref>.</p>
30126+
</emu-clause>
30127+
3011230128
<emu-clause id="sec-float32array">
3011330129
<h1>Float32Array ( . . . )</h1>
3011430130
<p>See <emu-xref href="#sec-typedarray-constructors"></emu-xref>.</p>
@@ -32752,6 +32768,23 @@ <h1>Math.fround ( _x_ )</h1>
3275232768
</emu-alg>
3275332769
</emu-clause>
3275432770

32771+
<emu-clause id="sec-math.f16round">
32772+
<h1>Math.f16round ( _x_ )</h1>
32773+
<p>This function performs the following steps when called:</p>
32774+
<emu-alg>
32775+
1. Let _n_ be ? ToNumber(_x_).
32776+
1. If _n_ is *NaN*, return *NaN*.
32777+
1. If _n_ is one of *+0*<sub>𝔽</sub>, *-0*<sub>𝔽</sub>, *+∞*<sub>𝔽</sub>, or *-∞*<sub>𝔽</sub>, return _n_.
32778+
1. Let _n16_ be the result of converting _n_ to IEEE 754-2019 binary16 format using roundTiesToEven mode.
32779+
1. Let _n64_ be the result of converting _n16_ to IEEE 754-2019 binary64 format.
32780+
1. Return the ECMAScript Number value corresponding to _n64_.
32781+
</emu-alg>
32782+
<emu-note>
32783+
<p>This operation is not the same as casting to binary32 and then to binary16 because of the possibility of double-rounding: consider the number _k_ = *1.00048828125000022204*<sub>𝔽</sub>, for example, for which Math.f16round(_k_) is *1.0009765625*<sub>𝔽</sub>, but Math.f16round(Math.fround(_k_)) is *1*<sub>𝔽</sub>.</p>
32784+
<p>Not all platforms provide native support for casting from binary64 to binary16. There are various libraries which can provide this, including the MIT-licensed <a href="https://half.sourceforge.net/">half</a> library. Alternatively, it is possible to first cast from binary64 to binary32 under roundTiesToEven and then check whether the result could lead to incorrect double-rounding. The cases which could can be handled explicitly by adjusting the mantissa of the binary32 value so that it is the value which would be produced by performing the initial cast under roundTiesToOdd. Casting the adjusted value to binary16 under roundTiesToEven then produces the correct value.</p>
32785+
</emu-note>
32786+
</emu-clause>
32787+
3275532788
<emu-clause id="sec-math.hypot">
3275632789
<h1>Math.hypot ( ..._args_ )</h1>
3275732790
<p>Given zero or more arguments, this function returns the square root of the sum of squares of its arguments.</p>
@@ -41123,6 +41156,23 @@ <h1>TypedArray Objects</h1>
4112341156
64-bit unsigned integer
4112441157
</td>
4112541158
</tr>
41159+
<tr>
41160+
<td>
41161+
Float16Array<br>
41162+
<dfn>%Float16Array%</dfn>
41163+
</td>
41164+
<td>
41165+
~float16~
41166+
</td>
41167+
<td>
41168+
2
41169+
</td>
41170+
<td>
41171+
</td>
41172+
<td>
41173+
16-bit IEEE floating point
41174+
</td>
41175+
</tr>
4112641176
<tr>
4112741177
<td>
4112841178
Float32Array<br>
@@ -44159,6 +44209,10 @@ <h1>
4415944209
<emu-alg>
4416044210
1. Let _elementSize_ be the Element Size value specified in <emu-xref href="#table-the-typedarray-constructors"></emu-xref> for Element Type _type_.
4416144211
1. If _isLittleEndian_ is *false*, reverse the order of the elements of _rawBytes_.
44212+
1. If _type_ is ~float16~, then
44213+
1. 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.
44214+
1. If _value_ is an IEEE 754-2019 binary16 NaN value, return the *NaN* Number value.
44215+
1. Return the Number value that corresponds to _value_.
4416244216
1. If _type_ is ~float32~, then
4416344217
1. 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.
4416444218
1. If _value_ is an IEEE 754-2019 binary32 NaN value, return the *NaN* Number value.
@@ -44242,7 +44296,9 @@ <h1>
4424244296
<dl class="header">
4424344297
</dl>
4424444298
<emu-alg>
44245-
1. If _type_ is ~float32~, then
44299+
1. If _type_ is ~float16~, then
44300+
1. 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.
44301+
1. Else if _type_ is ~float32~, then
4424644302
1. 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.
4424744303
1. Else if _type_ is ~float64~, then
4424844304
1. 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.
@@ -45175,6 +45231,16 @@ <h1>DataView.prototype.getBigUint64 ( _byteOffset_ [ , _littleEndian_ ] )</h1>
4517545231
</emu-alg>
4517645232
</emu-clause>
4517745233

45234+
<emu-clause id="sec-dataview.prototype.getfloat16">
45235+
<h1>DataView.prototype.getFloat16 ( _byteOffset_ [ , _littleEndian_ ] )</h1>
45236+
<p>This method performs the following steps when called:</p>
45237+
<emu-alg>
45238+
1. Let _v_ be the *this* value.
45239+
1. If _littleEndian_ is not present, set _littleEndian_ to *false*.
45240+
1. Return ? GetViewValue(_v_, _byteOffset_, _littleEndian_, ~float16~).
45241+
</emu-alg>
45242+
</emu-clause>
45243+
4517845244
<emu-clause id="sec-dataview.prototype.getfloat32">
4517945245
<h1>DataView.prototype.getFloat32 ( _byteOffset_ [ , _littleEndian_ ] )</h1>
4518045246
<p>This method performs the following steps when called:</p>
@@ -45271,6 +45337,16 @@ <h1>DataView.prototype.setBigUint64 ( _byteOffset_, _value_ [ , _littleEndian_ ]
4527145337
</emu-alg>
4527245338
</emu-clause>
4527345339

45340+
<emu-clause id="sec-dataview.prototype.setfloat16">
45341+
<h1>DataView.prototype.setFloat16 ( _byteOffset_, _value_ [ , _littleEndian_ ] )</h1>
45342+
<p>This method performs the following steps when called:</p>
45343+
<emu-alg>
45344+
1. Let _v_ be the *this* value.
45345+
1. If _littleEndian_ is not present, set _littleEndian_ to *false*.
45346+
1. Return ? SetViewValue(_v_, _byteOffset_, _littleEndian_, ~float16~, _value_).
45347+
</emu-alg>
45348+
</emu-clause>
45349+
4527445350
<emu-clause id="sec-dataview.prototype.setfloat32">
4527545351
<h1>DataView.prototype.setFloat32 ( _byteOffset_, _value_ [ , _littleEndian_ ] )</h1>
4527645352
<p>This method performs the following steps when called:</p>

0 commit comments

Comments
 (0)