Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gdtoa Merge the new gdtoa: Note that the built-in t...
details: https://anonhg.NetBSD.org/src/rev/7d6b3bd14e15
branches: trunk
changeset: 763465:7d6b3bd14e15
user: christos <christos%NetBSD.org@localhost>
date: Sun Mar 20 23:15:35 2011 +0000
description:
Merge the new gdtoa: Note that the built-in tests fail the same way as with
the old gdtoa.
diffstat:
lib/libc/gdtoa/dtoa.c | 201 +++++++++-------
lib/libc/gdtoa/g_Qfmt.c | 17 +-
lib/libc/gdtoa/g_ddfmt.c | 44 ++-
lib/libc/gdtoa/g_dfmt.c | 26 +-
lib/libc/gdtoa/g_ffmt.c | 17 +-
lib/libc/gdtoa/g_xLfmt.c | 17 +-
lib/libc/gdtoa/g_xfmt.c | 17 +-
lib/libc/gdtoa/gdtoa.c | 178 +++++++-------
lib/libc/gdtoa/gdtoa.h | 22 +-
lib/libc/gdtoa/gdtoaimp.h | 88 ++++--
lib/libc/gdtoa/gethex.c | 169 +++++++++++--
lib/libc/gdtoa/hexnan.c | 23 +-
lib/libc/gdtoa/makefile | 45 ++-
lib/libc/gdtoa/misc.c | 68 +++--
lib/libc/gdtoa/smisc.c | 33 +-
lib/libc/gdtoa/strtoIg.c | 20 +-
lib/libc/gdtoa/strtod.c | 528 +++++++++++++++++++++++++-----------------
lib/libc/gdtoa/strtodI.c | 90 +++---
lib/libc/gdtoa/strtodg.c | 201 ++++++++++------
lib/libc/gdtoa/strtodnrp.c | 10 +-
lib/libc/gdtoa/strtof.c | 11 +-
lib/libc/gdtoa/strtopQ.c | 11 +-
lib/libc/gdtoa/strtopd.c | 13 +-
lib/libc/gdtoa/strtopdd.c | 69 +++--
lib/libc/gdtoa/strtopf.c | 15 +-
lib/libc/gdtoa/strtopx.c | 14 +-
lib/libc/gdtoa/strtopxL.c | 14 +-
lib/libc/gdtoa/strtorQ.c | 14 +-
lib/libc/gdtoa/strtordd.c | 71 ++--
lib/libc/gdtoa/strtorf.c | 19 +-
lib/libc/gdtoa/strtorx.c | 22 +-
lib/libc/gdtoa/strtorxL.c | 22 +-
lib/libc/gdtoa/test/Qtest.c | 6 +-
lib/libc/gdtoa/test/makefile | 49 +--
lib/libc/gdtoa/test/xLtest.c | 6 +-
lib/libc/gdtoa/test/xtest.c | 6 +-
lib/libc/gdtoa/ulp.c | 22 +-
37 files changed, 1312 insertions(+), 886 deletions(-)
diffs (truncated from 4850 to 300 lines):
diff -r 150adfcb0c9d -r 7d6b3bd14e15 lib/libc/gdtoa/dtoa.c
--- a/lib/libc/gdtoa/dtoa.c Sun Mar 20 21:26:36 2011 +0000
+++ b/lib/libc/gdtoa/dtoa.c Sun Mar 20 23:15:35 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dtoa.c,v 1.5 2008/03/21 23:13:48 christos Exp $ */
+/* $NetBSD: dtoa.c,v 1.6 2011/03/20 23:15:35 christos Exp $ */
/****************************************************************
@@ -68,7 +68,6 @@
*/
#ifdef Honor_FLT_ROUNDS
-#define Rounding rounding
#undef Check_FLT_ROUNDS
#define Check_FLT_ROUNDS
#else
@@ -78,10 +77,10 @@
char *
dtoa
#ifdef KR_headers
- (d, mode, ndigits, decpt, sign, rve)
- double d; int mode, ndigits, *decpt, *sign; char **rve;
+ (d0, mode, ndigits, decpt, sign, rve)
+ double d0; int mode, ndigits, *decpt, *sign; char **rve;
#else
- (double d, int mode, int ndigits, int *decpt, int *sign, char **rve)
+ (double d0, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
{
/* Arguments ndigits, decpt, sign are similar to those
@@ -129,14 +128,25 @@
#endif
Bigint *b, *b1, *delta, *mhi, *S;
Bigint *mlo = NULL; /* pacify gcc */
- double d2, ds, eps;
+ U d, d2, eps;
+ double ds;
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) {
@@ -144,35 +154,35 @@
dtoa_result = 0;
}
#endif
-
- if (word0(d) & Sign_bit) {
+ d.d = d0;
+ if (word0(&d) & Sign_bit) {
/* set sign for everything, including 0's and NaNs */
*sign = 1;
- word0(d) &= ~Sign_bit; /* clear sign bit */
+ word0(&d) &= ~Sign_bit; /* clear sign bit */
}
else
*sign = 0;
#if defined(IEEE_Arith) + defined(VAX)
#ifdef IEEE_Arith
- if ((word0(d) & Exp_mask) == Exp_mask)
+ if ((word0(&d) & Exp_mask) == Exp_mask)
#else
- if (word0(d) == 0x8000)
+ if (word0(&d) == 0x8000)
#endif
{
/* Infinity or NaN */
*decpt = 9999;
#ifdef IEEE_Arith
- if (!word1(d) && !(word0(d) & 0xfffff))
+ if (!word1(&d) && !(word0(&d) & 0xfffff))
return nrv_alloc("Infinity", rve, 8);
#endif
return nrv_alloc("NaN", rve, 3);
}
#endif
#ifdef IBM
- dval(d) += 0; /* normalize */
+ dval(&d) += 0; /* normalize */
#endif
- if (!dval(d)) {
+ if (!dval(&d)) {
*decpt = 1;
return nrv_alloc("0", rve, 1);
}
@@ -182,37 +192,37 @@
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
- b = d2b(dval(d), &be, &bbits);
+ b = d2b(dval(&d), &be, &bbits);
if (b == NULL)
return NULL;
#ifdef Sudden_Underflow
- i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
+ i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
#else
- if (( i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) {
+ if (( i = (int)(word0(&d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)) )!=0) {
#endif
- dval(d2) = dval(d);
- word0(d2) &= Frac_mask1;
- word0(d2) |= Exp_11;
+ dval(&d2) = dval(&d);
+ word0(&d2) &= Frac_mask1;
+ word0(&d2) |= Exp_11;
#ifdef IBM
- if (( j = 11 - hi0bits(word0(d2) & Frac_mask) )!=0)
- dval(d2) /= 1 << j;
+ if (( j = 11 - hi0bits(word0(&d2) & Frac_mask) )!=0)
+ dval(&d2) /= 1 << j;
#endif
/* log(x) ~=~ log(1.5) + (x-1.5)/1.5
* log10(x) = log(x) / log(10)
* ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
- * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
+ * log10(&d) = (i-Bias)*log(2)/log(10) + log10(&d2)
*
- * This suggests computing an approximation k to log10(d) by
+ * This suggests computing an approximation k to log10(&d) by
*
* k = (i - Bias)*0.301029995663981
* + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
@@ -241,21 +251,21 @@
/* d is denormalized */
i = bbits + be + (Bias + (P-1) - 1);
- x = i > 32 ? word0(d) << (64 - i) | word1(d) >> (i - 32)
- : word1(d) << (32 - i);
- dval(d2) = x;
- word0(d2) -= 31*Exp_msk1; /* adjust exponent */
+ x = i > 32 ? word0(&d) << (64 - i) | word1(&d) >> (i - 32)
+ : word1(&d) << (32 - i);
+ dval(&d2) = x;
+ word0(&d2) -= 31*Exp_msk1; /* adjust exponent */
i -= (Bias + (P-1) - 1) + 1;
denorm = 1;
}
#endif
- ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+ ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
k = (int)ds;
if (ds < 0. && ds != k)
k--; /* want k = floor(ds) */
k_check = 1;
if (k >= 0 && k <= Ten_pmax) {
- if (dval(d) < tens[k])
+ if (dval(&d) < tens[k])
k--;
k_check = 0;
}
@@ -294,10 +304,11 @@
try_quick = 0;
}
leftright = 1;
+ ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */
+ /* silence erroneous "gcc -Wall" warning. */
switch(mode) {
case 0:
case 1:
- ilim = ilim1 = -1;
i = 18;
ndigits = 0;
break;
@@ -324,7 +335,7 @@
return NULL;
#ifdef Honor_FLT_ROUNDS
- if (mode > 1 && rounding != 1)
+ if (mode > 1 && Rounding != 1)
leftright = 0;
#endif
@@ -333,7 +344,7 @@
/* Try to get by with floating-point arithmetic. */
i = 0;
- dval(d2) = dval(d);
+ dval(&d2) = dval(&d);
k0 = k;
ilim0 = ilim;
ieps = 2; /* conservative */
@@ -343,7 +354,7 @@
if (j & Bletch) {
/* prevent overflows */
j &= Bletch - 1;
- dval(d) /= bigtens[n_bigtens-1];
+ dval(&d) /= bigtens[n_bigtens-1];
ieps++;
}
for(; j; j = (unsigned int)j >> 1, i++)
@@ -351,32 +362,32 @@
ieps++;
ds *= bigtens[i];
}
- dval(d) /= ds;
+ dval(&d) /= ds;
}
else if (( jj1 = -k )!=0) {
- dval(d) *= tens[jj1 & 0xf];
+ dval(&d) *= tens[jj1 & 0xf];
for(j = jj1 >> 4; j; j >>= 1, i++)
if (j & 1) {
ieps++;
- dval(d) *= bigtens[i];
+ dval(&d) *= bigtens[i];
}
}
- if (k_check && dval(d) < 1. && ilim > 0) {
+ if (k_check && dval(&d) < 1. && ilim > 0) {
if (ilim1 <= 0)
goto fast_failed;
ilim = ilim1;
k--;
- dval(d) *= 10.;
+ dval(&d) *= 10.;
ieps++;
}
- dval(eps) = ieps*dval(d) + 7.;
- word0(eps) -= (P-1)*Exp_msk1;
+ dval(&eps) = ieps*dval(&d) + 7.;
+ word0(&eps) -= (P-1)*Exp_msk1;
if (ilim == 0) {
S = mhi = 0;
- dval(d) -= 5.;
- if (dval(d) > dval(eps))
+ dval(&d) -= 5.;
+ if (dval(&d) > dval(&eps))
goto one_digit;
- if (dval(d) < -dval(eps))
+ if (dval(&d) < -dval(&eps))
goto no_digits;
goto fast_failed;
}
@@ -385,34 +396,34 @@
/* Use Steele & White method of only
* generating digits needed.
*/
- dval(eps) = 0.5/tens[ilim-1] - dval(eps);
+ dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);
for(i = 0;;) {
- L = dval(d);
- dval(d) -= L;
+ L = dval(&d);
+ dval(&d) -= L;
*s++ = '0' + (int)L;
- if (dval(d) < dval(eps))
+ if (dval(&d) < dval(&eps))
goto ret1;
- if (1. - dval(d) < dval(eps))
+ if (1. - dval(&d) < dval(&eps))
goto bump_up;
if (++i >= ilim)
break;
- dval(eps) *= 10.;
- dval(d) *= 10.;
+ dval(&eps) *= 10.;
+ dval(&d) *= 10.;
}
}
else {
#endif
/* Generate ilim digits, then fix them up. */
- dval(eps) *= tens[ilim-1];
- for(i = 1;; i++, dval(d) *= 10.) {
- L = (Long)(dval(d));
Home |
Main Index |
Thread Index |
Old Index