type E4M3 uint8 func (e4m3 E4M3) Float32() float32 { return lut[e4m3] } func (e4m3 E4M3) e8m23() uint32 { var ( all = uint32(e4m3) sign = all >> 7 exp = all >> 3 & 15 mant = all & 7 ret = sign << 31 ) switch { case exp == 0: if mant == 0 { return ret } exp = 127 - 7 mant <<= 1 for mant>>3 == 0 { mant <<= 1 exp-- } mant &= 7 case exp == 15 && mant == 7: return ret + 1<<31 - 1 default: exp += 127 - 7 } ret |= exp << 24 ret |= mant << 20 return ret } var lut [256]float32 func init() { for i := range &lut { e8m23 := E4M3(i).e8m23() lut[i] = math.Float32frombits(e8m23) } }
To receive a hint, submit unfixed code.