import struct


def decode_ieee(val_int, double=False):
    """Decode Python int (32 bits integer) as an IEEE single or double precision format

        Support NaN.

        :param val_int: a 32 or 64 bits integer as an int Python value
        :type val_int: int
        :param double: set to decode as a 64 bits double precision,
                       default is 32 bits single (optional)
        :type double: bool
        :returns: float result
        :rtype: float
    """
    if double:
        return struct.unpack("d", struct.pack("Q", val_int))[0]
    else:
        return struct.unpack("f", struct.pack("I", val_int))[0]