diff options
Diffstat (limited to 'source/f32_roundToInt.c')
-rw-r--r-- | source/f32_roundToInt.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/source/f32_roundToInt.c b/source/f32_roundToInt.c index 0861b84..801a769 100644 --- a/source/f32_roundToInt.c +++ b/source/f32_roundToInt.c @@ -2,7 +2,7 @@ /*============================================================================ This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic -Package, Release 3d, by John R. Hauser. +Package, Release 3e, by John R. Hauser. Copyright 2011, 2012, 2013, 2014, 2017 The Regents of the University of California. All rights reserved. @@ -57,12 +57,12 @@ float32_t f32_roundToInt( float32_t a, uint_fast8_t roundingMode, bool exact ) /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ if ( exp <= 0x7E ) { - if ( ! (uint32_t) (uiA<<1) ) return a; + if ( !(uint32_t) (uiA<<1) ) return a; if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact; uiZ = uiA & packToF32UI( 1, 0, 0 ); switch ( roundingMode ) { case softfloat_round_near_even: - if ( ! fracF32UI( uiA ) ) break; + if ( !fracF32UI( uiA ) ) break; case softfloat_round_near_maxMag: if ( exp == 0x7E ) uiZ |= packToF32UI( 0, 0x7F, 0 ); break; @@ -70,8 +70,13 @@ float32_t f32_roundToInt( float32_t a, uint_fast8_t roundingMode, bool exact ) if ( uiZ ) uiZ = packToF32UI( 1, 0x7F, 0 ); break; case softfloat_round_max: - if ( ! uiZ ) uiZ = packToF32UI( 0, 0x7F, 0 ); + if ( !uiZ ) uiZ = packToF32UI( 0, 0x7F, 0 ); break; +#ifdef SOFTFLOAT_ROUND_ODD + case softfloat_round_odd: + uiZ |= packToF32UI( 0, 0x7F, 0 ); + break; +#endif } goto uiZ; } @@ -93,7 +98,7 @@ float32_t f32_roundToInt( float32_t a, uint_fast8_t roundingMode, bool exact ) uiZ += lastBitMask>>1; } else if ( roundingMode == softfloat_round_near_even ) { uiZ += lastBitMask>>1; - if ( ! (uiZ & roundBitsMask) ) uiZ &= ~lastBitMask; + if ( !(uiZ & roundBitsMask) ) uiZ &= ~lastBitMask; } else if ( roundingMode == (signF32UI( uiZ ) ? softfloat_round_min : softfloat_round_max) @@ -101,8 +106,11 @@ float32_t f32_roundToInt( float32_t a, uint_fast8_t roundingMode, bool exact ) uiZ += roundBitsMask; } uiZ &= ~roundBitsMask; - if ( exact && (uiZ != uiA) ) { - softfloat_exceptionFlags |= softfloat_flag_inexact; + if ( uiZ != uiA ) { +#ifdef SOFTFLOAT_ROUND_ODD + if ( roundingMode == softfloat_round_odd ) uiZ |= lastBitMask; +#endif + if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact; } uiZ: uZ.ui = uiZ; |