Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.

Commit 2e69968

Browse files
authored
Editorial: add note about casting to f16 (#14)
1 parent 916f1b2 commit 2e69968

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

spec.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ <h1><ins>Math.f16round ( _x_ )</ins></h1>
4242
1. Let _n64_ be the result of converting _n16_ to IEEE 754-2019 binary64 format.
4343
1. Return the ECMAScript Number value corresponding to _n64_.
4444
</emu-alg>
45+
46+
<emu-note>
47+
<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 which Math.f16round(_k_) is *1.0009765625*<sub>𝔽</sub>, but Math.f16round(Math.fround(_k_)) is *1*<sub>𝔽</sub>.</p>
48+
<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>
49+
</emu-note>
4550
</emu-clause>
4651
</emu-clause>
4752

0 commit comments

Comments
 (0)