def build_ieee_extended(bitstream, value):
    """writes an 80-bit IEEE extended value to BitstreamWriter
    this is used to handle AIFF's sample rate field"""
    from math import frexp
    if value < 0:
        signed = 1
        value = abs(value)
    else:
        signed = 0
    fmant, exponent = frexp(value)
    if exponent > 16384 or fmant >= 1:
        exponent = 32767
        mantissa = 0
    else:
        exponent += 16382
        mantissa = fmant * 2 ** 64
    bitstream.build('1u 15u 64U', (signed, exponent, int(mantissa)))
