Dtype.bf16_rne: def of bendtorch@1.3.0.0 Import: import bendtorch@1.3.0.0/dtype.bend as Dtype Lines 43-46 of bendtorch@1.3.0.0/dtype.bend: https://jend.leeeet.dev/read.txt?path=bendtorch@1.3.0.0/dtype.bend&start_line=43&end_line=46 import Base # F32 -> BF16, round to nearest even: add 0x7FFF plus the lowest kept bit, keep the top half. The carry rounds up into # the exponent when the mantissa overflows, and past the largest finite value to infinity, as IEEE asks. def bf16_rne(+u: U32) -> U32: U32.shrn(((u + 32767 : U32) + (U32.shrn(u, 16n) .&. 1 : U32) : U32), 16n) Uses (4): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32 https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.add https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.and https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.shrn