kernels/linux-2.4.0/arch/arm/nwfpe/softfloat.c
/*
-------------------------------------------------------------------------------
Rounds the quadruple-precision floating-point value `a' to an integer, and
returns the result as a quadruple-precision floating-point value.  The
operation is performed according to the IEC/IEEE Standard for Binary
Floating-point Arithmetic.
-------------------------------------------------------------------------------
*/
Rounds the quadruple-precision floating-point value `a' to an integer, and
returns the result as a quadruple-precision floating-point value.  The
operation is performed according to the IEC/IEEE Standard for Binary
Floating-point Arithmetic.
Rounds the quadruple - precision floating - point value ` a ' to an integer and returns the result as a quadruple - precision floating - point value . The operation is performed according to the IEC / IEEE Standard for Binary Floating - point Arithmetic .
float128 float128_round_to_int( float128 a )
{
    flag aSign;
    int32 aExp;
    bits64 lastBitMask, roundBitsMask;
    int8 roundingMode;
    float128 z;
    aExp = extractFloat128Exp( a );
    if ( 0x402F <= aExp ) {
        if ( 0x406F <= aExp ) {
            if (    ( aExp == 0x7FFF )
                 && ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) )
               ) {
                return propagateFloat128NaN( a, a );
            }
            return a;
        }
        lastBitMask = 1;
        lastBitMask = ( lastBitMask<<( 0x406E - aExp ) )<<1;
        roundBitsMask = lastBitMask - 1;
        z = a;
        roundingMode = float_rounding_mode;
        if ( roundingMode == float_round_nearest_even ) {
            if ( lastBitMask ) {
                add128( z.high, z.low, 0, lastBitMask>>1, &z.high, &z.low );
                if ( ( z.low & roundBitsMask ) == 0 ) z.low &= ~ lastBitMask;
            }
            else {
                if ( (sbits64) z.low < 0 ) {
                    ++z.high;
                    if ( (bits64) ( z.low<<1 ) == 0 ) z.high &= ~1;
                }
            }
        }
        else if ( roundingMode != float_round_to_zero ) {
            if (   extractFloat128Sign( z )
                 ^ ( roundingMode == float_round_up ) ) {
                add128( z.high, z.low, 0, roundBitsMask, &z.high, &z.low );
            }
        }
        z.low &= ~ roundBitsMask;
    }
    else {
        if ( aExp <= 0x3FFE ) {
            if ( ( ( (bits64) ( a.high<<1 ) ) | a.low ) == 0 ) return a;
            float_exception_flags |= float_flag_inexact;
            aSign = extractFloat128Sign( a );
            switch ( float_rounding_mode ) {
             case float_round_nearest_even:
                if (    ( aExp == 0x3FFE )
                     && (   extractFloat128Frac0( a )
                          | extractFloat128Frac1( a ) )
                   ) {
                    return packFloat128( aSign, 0x3FFF, 0, 0 );
                }
                break;
             case float_round_down:
                return
                      aSign ? packFloat128( 1, 0x3FFF, 0, 0 )
                    : packFloat128( 0, 0, 0, 0 );
             case float_round_up:
                return
                      aSign ? packFloat128( 1, 0, 0, 0 )
                    : packFloat128( 0, 0x3FFF, 0, 0 );
            }
            return packFloat128( aSign, 0, 0, 0 );
        }
        lastBitMask = 1;
        lastBitMask <<= 0x402F - aExp;
        roundBitsMask = lastBitMask - 1;
        z.low = 0;
        z.high = a.high;
        roundingMode = float_rounding_mode;
        if ( roundingMode == float_round_nearest_even ) {
            z.high += lastBitMask>>1;
            if ( ( ( z.high & roundBitsMask ) | a.low ) == 0 ) {
                z.high &= ~ lastBitMask;
            }
        }
        else if ( roundingMode != float_round_to_zero ) {
            if (   extractFloat128Sign( z )
                 ^ ( roundingMode == float_round_up ) ) {
                z.high |= ( a.low != 0 );
                z.high += roundBitsMask;
            }
        }
        z.high &= ~ roundBitsMask;
    }
    if ( ( z.low != a.low ) || ( z.high != a.high ) ) {
        float_exception_flags |= float_flag_inexact;
    }
    return z;
}
float128 float128_round_to_int ( float128 a ) { flag aSign ; int32 aExp ; bits64 lastBitMask , roundBitsMask ; int8 roundingMode ; float128 z ; aExp = extractFloat128Exp ( a ) ; if ( 0x402F <= aExp ) { if ( 0x406F <= aExp ) { if ( ( aExp == 0x7FFF ) && ( extractFloat128Frac0 ( a ) | extractFloat128Frac1 ( a ) ) ) { return propagateFloat128NaN ( a , a ) ; } return a ; } lastBitMask = 1 ; lastBitMask = ( lastBitMask << ( 0x406E - aExp ) ) << 1 ; roundBitsMask = lastBitMask - 1 ; z = a ; roundingMode = float_rounding_mode ; if ( roundingMode == float_round_nearest_even ) { if ( lastBitMask ) { add128 ( z . high , z . low , 0 , lastBitMask >> 1 , & z . high , & z . low ) ; if ( ( z . low & roundBitsMask ) == 0 ) z . low &= ~ lastBitMask ; } else { if ( ( sbits64 ) z . low < 0 ) { ++ z . high ; if ( ( bits64 ) ( z . low << 1 ) == 0 ) z . high &= ~ 1 ; } } } else if ( roundingMode != float_round_to_zero ) { if ( extractFloat128Sign ( z ) ^ ( roundingMode == float_round_up ) ) { add128 ( z . high , z . low , 0 , roundBitsMask , & z . high , & z . low ) ; } } z . low &= ~ roundBitsMask ; } else { if ( aExp <= 0x3FFE ) { if ( ( ( ( bits64 ) ( a . high << 1 ) ) | a . low ) == 0 ) return a ; float_exception_flags |= float_flag_inexact ; aSign = extractFloat128Sign ( a ) ; switch ( float_rounding_mode ) { case float_round_nearest_even : if ( ( aExp == 0x3FFE ) && ( extractFloat128Frac0 ( a ) | extractFloat128Frac1 ( a ) ) ) { return packFloat128 ( aSign , 0x3FFF , 0 , 0 ) ; } break ; case float_round_down : return aSign ? packFloat128 ( 1 , 0x3FFF , 0 , 0 ) : packFloat128 ( 0 , 0 , 0 , 0 ) ; case float_round_up : return aSign ? packFloat128 ( 1 , 0 , 0 , 0 ) : packFloat128 ( 0 , 0x3FFF , 0 , 0 ) ; } return packFloat128 ( aSign , 0 , 0 , 0 ) ; } lastBitMask = 1 ; lastBitMask <<= 0x402F - aExp ; roundBitsMask = lastBitMask - 1 ; z . low = 0 ; z . high = a . high ; roundingMode = float_rounding_mode ; if ( roundingMode == float_round_nearest_even ) { z . high += lastBitMask >> 1 ; if ( ( ( z . high & roundBitsMask ) | a . low ) == 0 ) { z . high &= ~ lastBitMask ; } } else if ( roundingMode != float_round_to_zero ) { if ( extractFloat128Sign ( z ) ^ ( roundingMode == float_round_up ) ) { z . high |= ( a . low != 0 ) ; z . high += roundBitsMask ; } } z . high &= ~ roundBitsMask ; } if ( ( z . low != a . low ) || ( z . high != a . high ) ) { float_exception_flags |= float_flag_inexact ; } return z ; }
Rounds the quadruple-precision floating-point value `a' to an integer, and
returns the result as a quadruple-precision floating-point value.
Rounds the quadruple - precision floating - point value ` a ' to an integer and returns the result as a quadruple - precision floating - point value .