import struct


def float2bytes(f):
    """
    Convert float to bytes.
    :param f: float
    :return: 4 bytes
    """
    if isinstance(f, int):
        f = float(f)
    elif not isinstance(f, float):
        raise TypeError("f must be float")
    b = struct.pack("f", f)
    return b