Skip to main content

Module conversion

Module conversion 

Source
Expand description

Directed conversions between bfloat16 storage and f32.

#1785 asks for explicit bf16/f32 conversions in both directions with rounding and range behaviour that is stated rather than implied. Widening is exact, because every bfloat16 value is an f32; narrowing rounds to the nearest bfloat16, with ties to even, which is what half::bf16::from_f32 does. Neither direction is a promotion rule, and neither is implicit.

Functionsยง

narrow
Round every value to the nearest bfloat16, with ties to even.
widen
Widen every stored value to f32, which is exact.