Dtype.f16_normal: def of bendtorch@1.3.0.0 Import: import bendtorch@1.3.0.0/dtype.bend as Dtype Lines 66-71 of bendtorch@1.3.0.0/dtype.bend: https://jend.leeeet.dev/read.txt?path=bendtorch@1.3.0.0/dtype.bend&start_line=66&end_line=71 import Base # a normal F16 (|x| >= 2^-14): rebias the exponent (127 - 15 = 112), round the 23-bit mantissa to 10 bits to nearest # even; past 65504 the carry reaches the infinity pattern 0x7C00 and anything above it is infinity too def f16_normal(+a: U32) -> U32: +m = (a - 939524096 : U32) +r = U32.shrn(((m + 4095 : U32) + (U32.shrn(m, 13n) .&. 1 : U32) : U32), 13n) pick_u(U32.is_gt(r, 31744), 31744, r) Uses (7): 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.is_gt https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.shrn https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=U32.sub https://jend.leeeet.dev/definition.txt?path=bendtorch@1.3.0.0/dtype.bend&name=pick_u