aboutsummaryrefslogtreecommitdiff
path: root/source/s_roundToI32.c
diff options
context:
space:
mode:
authorJohn Hauser <jhauser@eecs.berkeley.edu>2018-01-26 12:51:15 -0800
committerJohn Hauser <jhauser@eecs.berkeley.edu>2018-01-26 12:51:15 -0800
commitf74b1e48110ac3a27dd49b787d164e55e42d81d1 (patch)
tree036feef8d982dff57c2f7fd6688deb4790865b10 /source/s_roundToI32.c
parent63d601476b7b2eefe72b1705b942eaa65db8c0bf (diff)
downloadberkeley-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/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;
/*------------------------------------------------------------------------