All problems
FP8 E4M3 Value Decode
Problem
Decode an 8-bit FP8 E4M3 value into its real number. The layout is 1 sign bit, 4 exponent bits with bias 7, and 3 mantissa bits; subnormals use 2^-6 with no implicit leading 1, and the code 0x7F is NaN. Return the decoded float for the integer bit pattern bits.
The signature is fp8_e4m3_decode(bits).
Hint
The exponent bias is 7 and the largest E4M3 magnitude is 448.
Test cases
case 1
in: [0]
expected: 0
case 2
in: [56]
expected: 1
case 3
in: [60]
expected: 1.5
case 4
in: [1]
expected: 0.001953125
case 5
in: [184]
expected: -1
Starter codePython
def fp8_e4m3_decode(bits):
# Your code here
pass5 test cases · run your code against them in the editor