Converts a float32 to the nearest half, rounding ties to the even significand. Called float32_to_float16 too.
- Values beyond the half range, from 65520 up, become infinity of the same sign (and fail an assert when
ASSERT_ON_OVERFLOWis on). An infinity input stays an infinity without that assert. - Values below the smallest normal half (2^-14) become subnormals, and ones that round to less than the smallest subnormal become signed zero.
- A NaN stays a NaN: the sign and the top bits of the payload are kept and the quiet bit is set, so a signalling NaN comes back quiet.
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 evenfloat_to_half_fast3 :: (_f: float32) -> Float16
Parameters
- _f: float32