pub fn f32_to_f24(float: f32) -> u32 {
    let bits = float.to_bits();

    let sign = bits & 0x80000000;
    let exponent = bits & 0x7f800000;
    let mantissa = bits & 0x007fffff;

    let result = if exponent == 0x7f800000 {
        if mantissa != 0 {
            // F is a NAN; we preserve the sign bit and
            // the 15 leftmost bits of the significand,
            // with one exception: If the 15 leftmost
            // bits are all zero, the NAN would turn
            // into an infinity, so we have to set at
            // least one bit in the significand.

            let mantissa = mantissa >> 8;
            (exponent >> 8) | mantissa | if mantissa == 0 { 1 } else { 0 }
        }
        else { // F is an infinity.
            exponent >> 8
        }
    }
    else { // F is finite, round the significand to 15 bits.
        let result = ((exponent | mantissa) + (mantissa & 0x00000080)) >> 8;

        if result >= 0x7f8000 {
            // F was close to FLT_MAX, and the significand was
            // rounded up, resulting in an exponent overflow.
            // Avoid the overflow by truncating the significand
            // instead of rounding it.

            (exponent | mantissa) >> 8
        }
        else {
            result
        }
    };

    return (sign >> 8) | result;
}
/// Conversion from 32-bit to 24-bit floating-point numbers.
/// Reverse conversion is just a simple 8-bit left shift.
Conversion from 32-bit to 24-bit floating-point numbers.
Reverse conversion is just a simple 8-bit left shift.
Conversion from 32 - bit to 24 - bit floating - point numbers . Reverse conversion is just a simple 8 - bit left shift .
pub fn f32_to_f24(float: f32) -> u32 {
    let bits = float.to_bits();
    let sign = bits & 0x80000000;
    let exponent = bits & 0x7f800000;
    let mantissa = bits & 0x007fffff;
    let result = if exponent == 0x7f800000 {
        if mantissa != 0 {
            // F is a NAN; we preserve the sign bit and
            // the 15 leftmost bits of the significand,
            // with one exception: If the 15 leftmost
            // bits are all zero, the NAN would turn
            // into an infinity, so we have to set at
            // least one bit in the significand.
            let mantissa = mantissa >> 8;
            (exponent >> 8) | mantissa | if mantissa == 0 { 1 } else { 0 }
        }
        else { // F is an infinity.
            exponent >> 8
        }
    }
    else { // F is finite, round the significand to 15 bits.
        let result = ((exponent | mantissa) + (mantissa & 0x00000080)) >> 8;
        if result >= 0x7f8000 {
            // F was close to FLT_MAX, and the significand was
            // rounded up, resulting in an exponent overflow.
            // Avoid the overflow by truncating the significand
            // instead of rounding it.
            (exponent | mantissa) >> 8
        }
        else {
            result
        }
    };
    return (sign >> 8) | result;
}
pub fn f32_to_f24 ( float : f32 ) -> u32 { let bits = float . to_bits ( ) ; let sign = bits & 0x80000000 ; let exponent = bits & 0x7f800000 ; let mantissa = bits & 0x007fffff ; let result = if exponent == 0x7f800000 { if mantissa != 0 { // F is a NAN; we preserve the sign bit and // the 15 leftmost bits of the significand, // with one exception: If the 15 leftmost // bits are all zero, the NAN would turn // into an infinity, so we have to set at // least one bit in the significand. let mantissa = mantissa >> 8 ; ( exponent >> 8 ) | mantissa | if mantissa == 0 { 1 } else { 0 } } else { // F is an infinity. exponent >> 8 } } else { // F is finite, round the significand to 15 bits. let result = ( ( exponent | mantissa ) + ( mantissa & 0x00000080 ) ) >> 8 ; if result >= 0x7f8000 { // F was close to FLT_MAX, and the significand was // rounded up, resulting in an exponent overflow. // Avoid the overflow by truncating the significand // instead of rounding it. ( exponent | mantissa ) >> 8 } else { result } } ; return ( sign >> 8 ) | result ; }
Conversion from 32-bit to 24-bit floating-point numbers.
Conversion from 32 - bit to 24 - bit floating - point numbers .
float
f32
float
f32