aboutsummaryrefslogtreecommitdiff
path: root/source/s_roundToI32.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/s_roundToI32.c')
-rw-r--r--source/s_roundToI32.c38
1 files changed, 26 insertions, 12 deletions
diff --git a/source/s_roundToI32.c b/source/s_roundToI32.c
index 20a3ff4..1999dcf 100644
--- a/source/s_roundToI32.c
+++ b/source/s_roundToI32.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, 2015, 2016, 2017 The Regents of the
University of California. All rights reserved.
@@ -45,7 +45,6 @@ int_fast32_t
softfloat_roundToI32(
bool sign, uint_fast64_t sig, uint_fast8_t roundingMode, bool exact )
{
- bool roundNearEven;
uint_fast16_t roundIncrement, roundBits;
uint_fast32_t sig32;
union { uint32_t ui; int32_t i; } uZ;
@@ -53,25 +52,40 @@ int_fast32_t
/*------------------------------------------------------------------------
*------------------------------------------------------------------------*/
- roundNearEven = (roundingMode == softfloat_round_near_even);
roundIncrement = 0x800;
- if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
- roundIncrement =
- (roundingMode
- == (sign ? softfloat_round_min : softfloat_round_max))
- ? 0xFFF
- : 0;
+ if (
+ (roundingMode != softfloat_round_near_maxMag)
+ && (roundingMode != softfloat_round_near_even)
+ ) {
+ roundIncrement = 0;
+ if (
+ sign
+ ? (roundingMode == softfloat_round_min)
+#ifdef SOFTFLOAT_ROUND_ODD
+ || (roundingMode == softfloat_round_odd)
+#endif
+ : (roundingMode == softfloat_round_max)
+ ) {
+ roundIncrement = 0xFFF;
+ }
}
roundBits = sig & 0xFFF;
sig += roundIncrement;
if ( sig & UINT64_C( 0xFFFFF00000000000 ) ) goto invalid;
sig32 = sig>>12;
- sig32 &= ~(uint_fast32_t) (! (roundBits ^ 0x800) & roundNearEven);
+ if (
+ (roundBits == 0x800) && (roundingMode == softfloat_round_near_even)
+ ) {
+ sig32 &= ~(uint_fast32_t) 1;
+ }
uZ.ui = sign ? -sig32 : sig32;
z = uZ.i;
if ( z && ((z < 0) ^ sign) ) goto invalid;
- if ( exact && roundBits ) {
- softfloat_exceptionFlags |= softfloat_flag_inexact;
+ if ( roundBits ) {
+#ifdef SOFTFLOAT_ROUND_ODD
+ if ( roundingMode == softfloat_round_odd ) z |= 1;
+#endif
+ if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact;
}
return z;
/*------------------------------------------------------------------------