# Number of bits of mantissa
m = 7

for a in range(1 << m):
    for b in range(4 << m):
        # We shift 'A' left by one to take account of the rounding bit.
        # 2<<m is the normalization bit.
        A = (2 << m) + (a << 1)
        # 'B' can have a half bit, so isn't shifted left
        B = b
        R = A + B
        S = 0
        if (R >> (m+2)) != 0:
            S = 1
            R = R >> 1
        R = R + 0x1
        if (R >> (m+2)) != 0:
            S += 2
            R = R >> 1
        # S:
        # 1 - we shifted after the addition
        # 2 - we shifted after rounding
        # 3 - we shifted after both
        #if S >= 2:
        print "%8x %8x  %9x %9x %d" % (A<<(30-m), B<<(30-m), (A+B)<<(30-m), R<<(30-m), S)

