Float16 module

float_to_half_fast3

procedure · 1 overloadSource

Converts a float32 to the nearest half, rounding ties to the even significand. Called float32_to_float16 too.

ExampleOpen in playground ↗
assert(cast(u16) float_to_half_fast3(1.0) == 0x3c00);
assert(cast(u16) float_to_half_fast3(-2.0) == 0xc000);
assert(cast(u16) float_to_half_fast3(65504.0) == 0x7bff);
assert(cast(u16) float_to_half_fast3(1.0 / 3.0) == 0x3555);
assert(cast(u16) float_to_half_fast3(100000.0) == 0x7c00); // overflow: infinity
assert(cast(u16) float_to_half_fast3(cast(float32) 1.00048828125) == 0x3c00); // tie rounds to even
float_to_half_fast3 :: (_f: float32) -> Float16

Parameters

_f: float32

Returns

See also