Skip to main content

from_f32

Function from_f32 

Source
pub fn from_f32(v: f32) -> u16
Expand description

Convert an f32 to IEEE half-float bits (round-to-nearest-even).

Values larger than 65504 become infinity (0x7C00/0xFC00), values smaller than the smallest subnormal become signed zero, NaN stays NaN.

assert_eq!(rolcb::float16::from_f32(0.5), 0x3800);
assert_eq!(rolcb::float16::from_f32(65504.0), 0x7BFF);