def tofloat(b16):
    sign = -1 if b16 & 32768 else +1
expo = (b16 & 31744) >> 10
prec = b16 & 1023
if expo == 0:
    return sign * 2.0 ** -24 * prec
elif expo == 31:
    return sign * float('inf')
prec |= 1024
binary16 in Python