elm-cardano/float16/1.0.0

Bytes.Floating.Decode

Extra Floating-point binary representation for Elm

float16 : Endianness -> Decoder Float

Decode 2 bytes as an IEEE 754 half-precision (16-bit) floating-point number, in the given byte order, and widen it to Elm's native Float (64-bit).

Half-precision layout (16 bits):

   exponent
          |        mantissa
sign      |               |
   |      |               |
   |      |               |
   | /---------\/-------------------\
   *  * * * * *  * * * * * * * * * *  (16-bit)

Interpretation by exponent value e:

e in [1..30] : normal    →  (-1)^s * 2^(e-15)   * (1 + m/1024)
e == 0, m/=0 : subnormal →  (-1)^s * 2^(-14)    * (0 + m/1024)
e == 0, m==0 : zero      →  +/- 0.0
e == 31, m==0: infinity  →  +/- Infinity
e == 31, m/=0: NaN

The conversion is exact: every float16 value is exactly representable in float64. The decoding uses pure arithmetic rather than bit reinterpretation through Bytes, making it ~35x faster than the float32-roundtrip approach.