diff options
-rw-r--r-- | lib/libc/stdlib/strtod.c | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/lib/libc/stdlib/strtod.c b/lib/libc/stdlib/strtod.c index 97b668c87..a6550d6 100644 --- a/lib/libc/stdlib/strtod.c +++ b/lib/libc/stdlib/strtod.c @@ -100,6 +100,7 @@ static char sccsid[] = "@(#)strtod.c 8.1 (Berkeley) 6/4/93"; * significant byte has the lowest address. * #define IEEE_BIG_ENDIAN for IEEE-arithmetic machines where the most * significant byte has the lowest address. + * #define Long int on machines with 32-bit ints and 64-bit longs. * #define Sudden_Underflow for IEEE-format machines without gradual * underflow (i.e., that flush to zero on underflow). * #define IBM for IBM mainframe-style floating-point arithmetic. @@ -114,7 +115,7 @@ static char sccsid[] = "@(#)strtod.c 8.1 (Berkeley) 6/4/93"; * #define ROUND_BIASED for IEEE-format with biased rounding. * #define Inaccurate_Divide for IEEE-format with correctly rounded * products but inaccurate quotients, e.g., for Intel i860. - * #define Just_16 to store 16 bits per 32-bit long when doing high-precision + * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision * integer arithmetic. Whether this speeds things up or slows things * down depends on the machine and the number being converted. * #define KR_headers for old-style C function headers. @@ -127,10 +128,15 @@ static char sccsid[] = "@(#)strtod.c 8.1 (Berkeley) 6/4/93"; #if defined(i386) || (defined(mips) && defined(MIPSEL)) || \ defined(__ia64__) || defined(__alpha__) -#define IEEE_LITTLE_ENDIAN -#else +#if BYTE_ORDER == BIG_ENDIAN #define IEEE_BIG_ENDIAN +#else +#define IEEE_LITTLE_ENDIAN #endif +#endif /* defined(__i386__) ... */ + +typedef int32_t Long; +typedef u_int32_t ULong; #ifdef DEBUG #include "stdio.h" @@ -153,6 +159,7 @@ static char sccsid[] = "@(#)strtod.c 8.1 (Berkeley) 6/4/93"; #include "errno.h" #include <ctype.h> + #ifdef Bad_float_h #undef __STDC__ #ifdef IEEE_BIG_ENDIAN @@ -222,11 +229,11 @@ Only one of IEEE_LITTLE_ENDIAN, IEEE_BIG_ENDIAN, VAX, or IBM should be defined. #endif #ifdef IEEE_LITTLE_ENDIAN -#define word0(x) ((u_int32_t *)&x)[1] -#define word1(x) ((u_int32_t *)&x)[0] +#define word0(x) ((ULong *)&x)[1] +#define word1(x) ((ULong *)&x)[0] #else -#define word0(x) ((u_int32_t *)&x)[0] -#define word1(x) ((u_int32_t *)&x)[1] +#define word0(x) ((ULong *)&x)[0] +#define word1(x) ((ULong *)&x)[1] #endif /* The following definition of Storeinc is appropriate for MIPS processors. @@ -349,10 +356,10 @@ extern double rnd_prod(double, double), rnd_quot(double, double); #define Big1 0xffffffff #ifndef Just_16 -/* When Pack_32 is not defined, we store 16 bits per 32-bit long. +/* When Pack_32 is not defined, we store 16 bits per 32-bit Long. * This makes some inner loops simpler and sometimes saves work * during multiplications, but it often seems to make things slightly - * slower. Hence the default is now to store 32 bits per long. + * slower. Hence the default is now to store 32 bits per Long. */ #ifndef Pack_32 #define Pack_32 @@ -371,7 +378,7 @@ extern "C" char *__dtoa(double d, int mode, int ndigits, Bigint { struct Bigint *next; int k, maxwds, sign, wds; - unsigned long x[1]; + ULong x[1]; }; typedef struct Bigint Bigint; @@ -388,7 +395,7 @@ Balloc Bigint *rv; x = 1 << k; - rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(long)); + rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(Long)); rv->k = k; rv->maxwds = x; rv->sign = rv->wds = 0; @@ -407,7 +414,7 @@ Bfree } #define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \ -y->wds*sizeof(long) + 2*sizeof(int)) +y->wds*sizeof(Long) + 2*sizeof(int)) static Bigint * multadd @@ -418,9 +425,9 @@ multadd #endif { int i, wds; - unsigned long *x, y; + ULong *x, y; #ifdef Pack_32 - unsigned long xi, z; + ULong xi, z; #endif Bigint *b1; @@ -456,14 +463,14 @@ multadd static Bigint * s2b #ifdef KR_headers - (s, nd0, nd, y9) CONST char *s; int nd0, nd; unsigned long y9; + (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; #else - (CONST char *s, int nd0, int nd, unsigned long y9) + (CONST char *s, int nd0, int nd, ULong y9) #endif { Bigint *b; int i, k; - long x, y; + Long x, y; x = (nd + 8) / 9; for (k = 0, y = 1; x > y; y <<= 1, k++) ; @@ -494,12 +501,12 @@ s2b static int hi0bits #ifdef KR_headers - (x) register unsigned long x; + (x) ULong x; #else - (register unsigned long x) + (ULong x) #endif { - register int k = 0; + int k = 0; if (!(x & 0xffff0000)) { k = 16; @@ -528,13 +535,13 @@ hi0bits static int lo0bits #ifdef KR_headers - (y) unsigned long *y; + (y) ULong *y; #else - (unsigned long *y) + (ULong *y) #endif { - register int k; - register unsigned long x = *y; + int k; + ULong x = *y; if (x & 7) { if (x & 1) @@ -599,10 +606,10 @@ mult { Bigint *c; int k, wa, wb, wc; - unsigned long carry, y, z; - unsigned long *x, *xa, *xae, *xb, *xbe, *xc, *xc0; + ULong carry, y, z; + ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0; #ifdef Pack_32 - unsigned long z2; + ULong z2; #endif if (a->wds < b->wds) { @@ -725,7 +732,7 @@ lshift { int i, k1, n, n1; Bigint *b1; - unsigned long *x, *x1, *xe, z; + ULong *x, *x1, *xe, z; #ifdef Pack_32 n = k >> 5; @@ -782,7 +789,7 @@ cmp (Bigint *a, Bigint *b) #endif { - unsigned long *xa, *xa0, *xb, *xb0; + ULong *xa, *xa0, *xb, *xb0; int i, j; i = a->wds; @@ -818,10 +825,10 @@ diff { Bigint *c; int i, wa, wb; - long borrow, y; /* We need signed shifts here. */ - unsigned long *xa, *xae, *xb, *xbe, *xc; + Long borrow, y; /* We need signed shifts here. */ + ULong *xa, *xae, *xb, *xbe, *xc; #ifdef Pack_32 - long z; + Long z; #endif i = cmp(a,b); @@ -895,7 +902,7 @@ ulp (double x) #endif { - register long L; + Long L; double a; L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; @@ -931,11 +938,11 @@ b2d (Bigint *a, int *e) #endif { - unsigned long *xa, *xa0, w, y, z; + ULong *xa, *xa0, w, y, z; int k; double d; #ifdef VAX - unsigned long d0, d1; + ULong d0, d1; #else #define d0 word0(d) #define d1 word1(d) @@ -1002,9 +1009,9 @@ d2b { Bigint *b; int de, i, k; - unsigned long *x, y, z; + ULong *x, y, z; #ifdef VAX - unsigned long d0, d1; + ULong d0, d1; d0 = word0(d) >> 16 | word0(d) << 16; d1 = word1(d) >> 16 | word1(d) << 16; #else @@ -1195,8 +1202,8 @@ strtod e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; CONST char *s, *s0, *s1; double aadj, aadj1, adj, rv, rv0; - long L; - unsigned long y, z; + Long L; + ULong y, z; Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; char decimal_point = localeconv()->decimal_point[0]; @@ -1707,12 +1714,12 @@ quorem #endif { int n; - long borrow, y; - unsigned long carry, q, ys; - unsigned long *bx, *bxe, *sx, *sxe; + Long borrow, y; + ULong carry, q, ys; + ULong *bx, *bxe, *sx, *sxe; #ifdef Pack_32 - long z; - unsigned long si, zs; + Long z; + ULong si, zs; #endif n = S->wds; @@ -1832,7 +1839,7 @@ quorem * guarantee that the floating-point calculation has given * the correctly rounded result. For k requested digits and * "uniformly" distributed input, the probability is - * something like 10^(k-15) that we must resort to the long + * something like 10^(k-15) that we must resort to the Long * calculation. */ @@ -1883,10 +1890,10 @@ __dtoa int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, spec_case, try_quick; - long L; + Long L; #ifndef Sudden_Underflow int denorm; - unsigned long x; + ULong x; #endif Bigint *b, *b1, *delta, *mlo, *mhi, *S; double d2, ds, eps; |