Math module

half_to_float

procedure · 1 overloadSource

Converts the 16 bits of an IEEE half-precision float to a float, exactly (subnormals, infinities and NaN included). The Float16 module wraps this with typed halves and the opposite direction.

ExampleOpen in playground ↗
assert(half_to_float(0x3c00) == 1.0);
assert(half_to_float(0xc000) == -2.0);
assert(half_to_float(0x7bff) == 65504.0);
half_to_float :: (h: u16) -> float

Converts a 16-bit half-precision float (given as its raw bits) to a float.

Parameters

h: u16
the bits of the half float.

Returns

float

See also