type E4M3 uint8 func NewE4M3(from float32) E4M3 { var ( all = math.Float32bits(from) sign = all >> 31 exp = all >> 23 & 255 mant = all & (1<<23 - 1) ret = sign << 7 ) switch { case exp <= 127-7: shift := 127 - 7 - exp + 1 if shift > 4 { return E4M3(ret) } mant |= 1 << 23 mant |= mant & 15 << 4 mant >>= shift ret |= mant >> 20 case exp <= 127+8: ret |= (exp - 127 + 7) << 3 ret |= mant >> 20 if ret&127 >= 126 { return E4M3(ret &^ 1) } case exp != 255 || mant != 0: return E4M3(ret | 126) default: return E4M3(ret | 127) } switch { case mant&(1<<19) == 0: case mant&(3<<19-1) != 0: ret++ } return E4M3(ret) }
To receive a hint, submit unfixed code.