aboutsummaryrefslogtreecommitdiff
path: root/source/s_roundPackToF16.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/s_roundPackToF16.c')
-rw-r--r--source/s_roundPackToF16.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/source/s_roundPackToF16.c b/source/s_roundPackToF16.c
index f85b0bd..b37580a 100644
--- a/source/s_roundPackToF16.c
+++ b/source/s_roundPackToF16.c
@@ -2,9 +2,9 @@
/*============================================================================
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
-Package, Release 3b, by John R. Hauser.
+Package, Release 3c, by John R. Hauser.
-Copyright 2011, 2012, 2013, 2014, 2015 The Regents of the University of
+Copyright 2011, 2012, 2013, 2014, 2015, 2017 The Regents of the University of
California. All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,8 @@ float16_t
uint_fast16_t uiZ;
union ui16_f16 uZ;
+ /*------------------------------------------------------------------------
+ *------------------------------------------------------------------------*/
roundingMode = softfloat_roundingMode;
roundNearEven = (roundingMode == softfloat_round_near_even);
roundIncrement = 0x8;
@@ -61,8 +63,12 @@ float16_t
: 0;
}
roundBits = sig & 0xF;
+ /*------------------------------------------------------------------------
+ *------------------------------------------------------------------------*/
if ( 0x1D <= (unsigned int) exp ) {
if ( exp < 0 ) {
+ /*----------------------------------------------------------------
+ *----------------------------------------------------------------*/
isTiny =
(softfloat_detectTininess == softfloat_tininess_beforeRounding)
|| (exp < -1) || (sig + roundIncrement < 0x8000);
@@ -73,16 +79,32 @@ float16_t
softfloat_raiseFlags( softfloat_flag_underflow );
}
} else if ( (0x1D < exp) || (0x8000 <= sig + roundIncrement) ) {
+ /*----------------------------------------------------------------
+ *----------------------------------------------------------------*/
softfloat_raiseFlags(
softfloat_flag_overflow | softfloat_flag_inexact );
uiZ = packToF16UI( sign, 0x1F, 0 ) - ! roundIncrement;
goto uiZ;
}
}
- if ( roundBits ) softfloat_exceptionFlags |= softfloat_flag_inexact;
+ /*------------------------------------------------------------------------
+ *------------------------------------------------------------------------*/
sig = (sig + roundIncrement)>>4;
+ if ( roundBits ) {
+ softfloat_exceptionFlags |= softfloat_flag_inexact;
+#ifdef SOFTFLOAT_ROUND_ODD
+ if ( roundingMode == softfloat_round_odd ) {
+ sig |= 1;
+ goto packReturn;
+ }
+#endif
+ }
sig &= ~(uint_fast16_t) (! (roundBits ^ 8) & roundNearEven);
- uiZ = packToF16UI( sign, sig ? exp : 0, sig );
+ if ( ! sig ) exp = 0;
+ /*------------------------------------------------------------------------
+ *------------------------------------------------------------------------*/
+ packReturn:
+ uiZ = packToF16UI( sign, exp, sig );
uiZ:
uZ.ui = uiZ;
return uZ.f;