diff options
author | John Hauser <jhauser@eecs.berkeley.edu> | 2018-01-26 12:51:15 -0800 |
---|---|---|
committer | John Hauser <jhauser@eecs.berkeley.edu> | 2018-01-26 12:51:15 -0800 |
commit | f74b1e48110ac3a27dd49b787d164e55e42d81d1 (patch) | |
tree | 036feef8d982dff57c2f7fd6688deb4790865b10 /source/f64_roundToInt.c | |
parent | 63d601476b7b2eefe72b1705b942eaa65db8c0bf (diff) | |
download | berkeley-softfloat-3-f74b1e48110ac3a27dd49b787d164e55e42d81d1.zip berkeley-softfloat-3-f74b1e48110ac3a27dd49b787d164e55e42d81d1.tar.gz berkeley-softfloat-3-f74b1e48110ac3a27dd49b787d164e55e42d81d1.tar.bz2 |
Release 3e. See "doc/SoftFloat-history.html".
Diffstat (limited to 'source/f64_roundToInt.c')
-rw-r--r-- | source/f64_roundToInt.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/source/f64_roundToInt.c b/source/f64_roundToInt.c index 7f81007..c5f08ae 100644 --- a/source/f64_roundToInt.c +++ b/source/f64_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 @@ float64_t f64_roundToInt( float64_t a, uint_fast8_t roundingMode, bool exact ) /*------------------------------------------------------------------------ *------------------------------------------------------------------------*/ if ( exp <= 0x3FE ) { - if ( ! (uiA & UINT64_C( 0x7FFFFFFFFFFFFFFF )) ) return a; + if ( !(uiA & UINT64_C( 0x7FFFFFFFFFFFFFFF )) ) return a; if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact; uiZ = uiA & packToF64UI( 1, 0, 0 ); switch ( roundingMode ) { case softfloat_round_near_even: - if ( ! fracF64UI( uiA ) ) break; + if ( !fracF64UI( uiA ) ) break; case softfloat_round_near_maxMag: if ( exp == 0x3FE ) uiZ |= packToF64UI( 0, 0x3FF, 0 ); break; @@ -70,8 +70,13 @@ float64_t f64_roundToInt( float64_t a, uint_fast8_t roundingMode, bool exact ) if ( uiZ ) uiZ = packToF64UI( 1, 0x3FF, 0 ); break; case softfloat_round_max: - if ( ! uiZ ) uiZ = packToF64UI( 0, 0x3FF, 0 ); + if ( !uiZ ) uiZ = packToF64UI( 0, 0x3FF, 0 ); break; +#ifdef SOFTFLOAT_ROUND_ODD + case softfloat_round_odd: + uiZ |= packToF64UI( 0, 0x3FF, 0 ); + break; +#endif } goto uiZ; } @@ -93,7 +98,7 @@ float64_t f64_roundToInt( float64_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 == (signF64UI( uiZ ) ? softfloat_round_min : softfloat_round_max) @@ -101,8 +106,11 @@ float64_t f64_roundToInt( float64_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; |