summaryrefslogtreecommitdiff
path: root/lib/libc/gdtoa/dtoa.c
diff options
context:
space:
mode:
authorMartynas Venckus <martynas@cvs.openbsd.org>2008-12-09 19:44:11 +0000
committerMartynas Venckus <martynas@cvs.openbsd.org>2008-12-09 19:44:11 +0000
commitfdb65fd80a5ceacbd684d17ad6893767c441474d (patch)
tree706246875706ed26bf03d21b04ffeb93d66d5422 /lib/libc/gdtoa/dtoa.c
parent215e2c76fd697cf5848ca1f079861699d88c764e (diff)
bugfix update to gdtoa 2008-10-10. ok millert@, tested by many
Diffstat (limited to 'lib/libc/gdtoa/dtoa.c')
-rw-r--r--lib/libc/gdtoa/dtoa.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/lib/libc/gdtoa/dtoa.c b/lib/libc/gdtoa/dtoa.c
index e808cc1f4f3..48fdf5efc2d 100644
--- a/lib/libc/gdtoa/dtoa.c
+++ b/lib/libc/gdtoa/dtoa.c
@@ -66,7 +66,6 @@ THIS SOFTWARE.
*/
#ifdef Honor_FLT_ROUNDS
-#define Rounding rounding
#undef Check_FLT_ROUNDS
#define Check_FLT_ROUNDS
#else
@@ -127,12 +126,22 @@ dtoa
Bigint *b, *b1, *delta, *mlo, *mhi, *S;
double d2, ds, eps;
char *s, *s0;
-#ifdef Honor_FLT_ROUNDS
- int rounding;
-#endif
#ifdef SET_INEXACT
int inexact, oldinexact;
#endif
+#ifdef Honor_FLT_ROUNDS /*{*/
+ int Rounding;
+#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
+ Rounding = Flt_Rounds;
+#else /*}{*/
+ Rounding = 1;
+ switch(fegetround()) {
+ case FE_TOWARDZERO: Rounding = 0; break;
+ case FE_UPWARD: Rounding = 2; break;
+ case FE_DOWNWARD: Rounding = 3;
+ }
+#endif /*}}*/
+#endif /*}*/
#ifndef MULTIPLE_THREADS
if (dtoa_result) {
@@ -178,12 +187,12 @@ dtoa
inexact = 1;
#endif
#ifdef Honor_FLT_ROUNDS
- if ((rounding = Flt_Rounds) >= 2) {
+ if (Rounding >= 2) {
if (*sign)
- rounding = rounding == 2 ? 0 : 2;
+ Rounding = Rounding == 2 ? 0 : 2;
else
- if (rounding != 2)
- rounding = 0;
+ if (Rounding != 2)
+ Rounding = 0;
}
#endif
@@ -316,7 +325,7 @@ dtoa
s = s0 = rv_alloc(i);
#ifdef Honor_FLT_ROUNDS
- if (mode > 1 && rounding != 1)
+ if (mode > 1 && Rounding != 1)
leftright = 0;
#endif
@@ -453,7 +462,7 @@ dtoa
if (i == ilim) {
#ifdef Honor_FLT_ROUNDS
if (mode > 1)
- switch(rounding) {
+ switch(Rounding) {
case 0: goto ret1;
case 2: goto bump_up;
}
@@ -521,7 +530,7 @@ dtoa
spec_case = 0;
if ((mode < 2 || leftright)
#ifdef Honor_FLT_ROUNDS
- && rounding == 1
+ && Rounding == 1
#endif
) {
if (!word1(d) && !(word0(d) & Bndry_mask)
@@ -614,7 +623,7 @@ dtoa
#ifndef ROUND_BIASED
if (j1 == 0 && mode != 1 && !(word1(d) & 1)
#ifdef Honor_FLT_ROUNDS
- && rounding >= 1
+ && Rounding >= 1
#endif
) {
if (dig == '9')
@@ -642,7 +651,7 @@ dtoa
}
#ifdef Honor_FLT_ROUNDS
if (mode > 1)
- switch(rounding) {
+ switch(Rounding) {
case 0: goto accept_dig;
case 2: goto keep_dig;
}
@@ -660,7 +669,7 @@ dtoa
}
if (j1 > 0) {
#ifdef Honor_FLT_ROUNDS
- if (!rounding)
+ if (!Rounding)
goto accept_dig;
#endif
if (dig == '9') { /* possible if i == 1 */
@@ -703,7 +712,7 @@ dtoa
/* Round off last digit */
#ifdef Honor_FLT_ROUNDS
- switch(rounding) {
+ switch(Rounding) {
case 0: goto trimzeros;
case 2: goto roundoff;
}