2009-04-13 Ozkan Sezer <sezeroz@gmail.com>

* gdtoa/dmisc.c, gdtoa/dtoa.c, gdtoa/g__fmt.c, gdtoa/g_dfmt.c,
	gdtoa/g_ffmt.c, gdtoa/g_xfmt.c, gdtoa/gdtoa.c, gdtoa/gdtoa.h,
	gdtoa/gdtoaimp.h, gdtoa/gethex.c, gdtoa/gmisc.c, gdtoa/hd_init.c,
	gdtoa/hexnan.c, gdtoa/misc.c, gdtoa/smisc.c, gdtoa/strtodg.c,
	gdtoa/strtodnrp.c, gdtoa/strtof.c, gdtoa/strtopx.c, gdtoa/sum.c,
	gdtoa/ulp.c: Removed all KR_headers stuff along with ANSI, CONST,
	Void and Char things. Aligned the closing braces with the opening
	braces (wnitespace.)


git-svn-id: svn+ssh://svn.code.sf.net/p/mingw-w64/code/trunk@761 4407c894-4637-0410-b4f5-ada5f102cad1
This commit is contained in:
Ozkan Sezer 2009-04-13 15:02:01 +00:00
parent e0878a7012
commit 455ce8bb0d
22 changed files with 608 additions and 933 deletions

View File

@ -1,3 +1,13 @@
2009-04-13 Ozkan Sezer <sezeroz@gmail.com>
* gdtoa/dmisc.c, gdtoa/dtoa.c, gdtoa/g__fmt.c, gdtoa/g_dfmt.c,
gdtoa/g_ffmt.c, gdtoa/g_xfmt.c, gdtoa/gdtoa.c, gdtoa/gdtoa.h,
gdtoa/gdtoaimp.h, gdtoa/gethex.c, gdtoa/gmisc.c, gdtoa/hd_init.c,
gdtoa/hexnan.c, gdtoa/misc.c, gdtoa/smisc.c, gdtoa/strtodg.c,
gdtoa/strtodnrp.c, gdtoa/strtof.c, gdtoa/strtopx.c, gdtoa/sum.c,
gdtoa/ulp.c: Removed all KR_headers stuff along with ANSI, CONST,
Void and Char things. Aligned the closing braces with the opening
braces (wnitespace.)
2009-04-13 Ozkan Sezer <sezeroz@gmail.com>
* gdtoa/dtoa.c, gdtoa/gdtoa.c, gdtoa/gdtoaimp.h, gdtoa/misc.c,

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
char *
#ifdef KR_headers
rv_alloc(i) int i;
#else
rv_alloc(int i)
#endif
char *rv_alloc (int i)
{
int j, k, *r;
@ -52,14 +47,9 @@ rv_alloc(int i)
dtoa_result =
#endif
(char *)(r+1);
}
}
char *
#ifdef KR_headers
nrv_alloc(s, rve, n) char *s, **rve; int n;
#else
nrv_alloc(char *s, char **rve, int n)
#endif
char *nrv_alloc (char *s, char **rve, int n)
{
char *rv, *t;
@ -69,7 +59,7 @@ nrv_alloc(char *s, char **rve, int n)
if (rve)
*rve = t;
return rv;
}
}
/* freedtoa(s) must be used to free values s returned by dtoa
* when MULTIPLE_THREADS is #defined. It should be used in all cases,
@ -77,12 +67,7 @@ nrv_alloc(char *s, char **rve, int n)
* when MULTIPLE_THREADS is not defined.
*/
void
#ifdef KR_headers
__freedtoa(s) char *s;
#else
__freedtoa(char *s)
#endif
void __freedtoa (char *s)
{
Bigint *b = (Bigint *)((int *)s - 1);
b->maxwds = 1 << (b->k = *(int*)b);
@ -91,15 +76,9 @@ __freedtoa(char *s)
if (s == dtoa_result)
dtoa_result = 0;
#endif
}
}
int
quorem
#ifdef KR_headers
(b, S) Bigint *b, *S;
#else
(Bigint *b, Bigint *S)
#endif
int quorem (Bigint *b, Bigint *S)
{
int n;
ULong *bx, *bxe, q, *sx, *sxe;
@ -157,15 +136,16 @@ quorem
*bx++ = y & 0xffff;
#endif
#endif
}
while(sx <= sxe);
} while(sx <= sxe);
if (!*bxe) {
bx = b->x;
while(--bxe > bx && !*bxe)
--n;
b->wds = n;
}
}
}
if (cmp(b, S) >= 0) {
q++;
borrow = 0;
@ -198,15 +178,15 @@ quorem
*bx++ = y & 0xffff;
#endif
#endif
}
while(sx <= sxe);
} while(sx <= sxe);
bx = b->x;
bxe = bx + n;
if (!*bxe) {
while(--bxe > bx && !*bxe)
--n;
b->wds = n;
}
}
return q;
}
return q;
}

View File

@ -73,14 +73,7 @@ THIS SOFTWARE.
#define Rounding Flt_Rounds
#endif
char *
__dtoa
#ifdef KR_headers
(val, mode, ndigits, decpt, sign, rve)
double val; int mode, ndigits, *decpt, *sign; char **rve;
#else
(double val, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
char *__dtoa (double val, int mode, int ndigits, int *decpt, int *sign, char **rve)
{
/* Arguments ndigits, decpt, sign are similar to those
of ecvt and fcvt; trailing zeros are suppressed from
@ -145,14 +138,14 @@ __dtoa
if (dtoa_result) {
__freedtoa(dtoa_result);
dtoa_result = 0;
}
}
#endif
if (word0(d) & Sign_bit) {
/* set sign for everything, including 0's and NaNs */
*sign = 1;
word0(d) &= ~Sign_bit; /* clear sign bit */
}
}
else
*sign = 0;
@ -162,7 +155,7 @@ __dtoa
#else
if (word0(d) == 0x8000)
#endif
{
{
/* Infinity or NaN */
*decpt = 9999;
#ifdef IEEE_Arith
@ -170,7 +163,7 @@ __dtoa
return nrv_alloc("Infinity", rve, 8);
#endif
return nrv_alloc("NaN", rve, 3);
}
}
#endif
#ifdef IBM
dval(d) += 0; /* normalize */
@ -178,7 +171,7 @@ __dtoa
if (!dval(d)) {
*decpt = 1;
return nrv_alloc("0", rve, 1);
}
}
#ifdef SET_INEXACT
try_quick = oldinexact = get_inexact();
@ -191,7 +184,7 @@ __dtoa
else
if (rounding != 2)
rounding = 0;
}
}
#endif
b = d2b(dval(d), &be, &bbits);
@ -237,7 +230,7 @@ __dtoa
#endif
#ifndef Sudden_Underflow
denorm = 0;
}
}
else {
/* d is denormalized */
@ -248,7 +241,7 @@ __dtoa
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;
k = (int)ds;
@ -259,26 +252,26 @@ __dtoa
if (dval(d) < tens[k])
k--;
k_check = 0;
}
}
j = bbits - i - 1;
if (j >= 0) {
b2 = 0;
s2 = j;
}
}
else {
b2 = -j;
s2 = 0;
}
}
if (k >= 0) {
b5 = 0;
s5 = k;
s2 += k;
}
}
else {
b2 -= k;
b5 = -k;
s5 = 0;
}
}
if (mode < 0 || mode > 9)
mode = 0;
@ -293,7 +286,7 @@ __dtoa
if (mode > 5) {
mode -= 4;
try_quick = 0;
}
}
leftright = 1;
switch(mode) {
case 0:
@ -319,7 +312,7 @@ __dtoa
ilim1 = i - 1;
if (i <= 0)
i = 1;
}
}
s = s0 = rv_alloc(i);
#ifdef Honor_FLT_ROUNDS
@ -328,9 +321,7 @@ __dtoa
#endif
if (ilim >= 0 && ilim <= Quick_max && try_quick) {
/* Try to get by with floating-point arithmetic. */
i = 0;
dval(d2) = dval(d);
k0 = k;
@ -344,22 +335,22 @@ __dtoa
j &= Bletch - 1;
dval(d) /= bigtens[n_bigtens-1];
ieps++;
}
}
for(; j; j >>= 1, i++)
if (j & 1) {
ieps++;
ds *= bigtens[i];
}
}
dval(d) /= ds;
}
}
else if (( j1 = -k )!=0) {
dval(d) *= tens[j1 & 0xf];
for(j = j1 >> 4; j; j >>= 1, i++)
if (j & 1) {
ieps++;
dval(d) *= bigtens[i];
}
}
}
}
if (k_check && dval(d) < 1. && ilim > 0) {
if (ilim1 <= 0)
goto fast_failed;
@ -367,7 +358,7 @@ __dtoa
k--;
dval(d) *= 10.;
ieps++;
}
}
dval(eps) = ieps*dval(d) + 7.;
word0(eps) -= (P-1)*Exp_msk1;
if (ilim == 0) {
@ -378,7 +369,7 @@ __dtoa
if (dval(d) < -dval(eps))
goto no_digits;
goto fast_failed;
}
}
#ifndef No_leftright
if (leftright) {
/* Use Steele & White method of only
@ -397,8 +388,8 @@ __dtoa
break;
dval(eps) *= 10.;
dval(d) *= 10.;
}
}
}
else {
#endif
/* Generate ilim digits, then fix them up. */
@ -415,19 +406,19 @@ __dtoa
while(*--s == '0');
s++;
goto ret1;
}
break;
}
break;
}
#ifndef No_leftright
}
#ifndef No_leftright
}
#endif
fast_failed:
s = s0;
dval(d) = dval(d2);
k = k0;
ilim = ilim0;
}
}
/* Do we have a "small" integer? */
@ -439,7 +430,7 @@ __dtoa
if (ilim < 0 || dval(d) <= 5*ds)
goto no_digits;
goto one_digit;
}
}
for(i = 1;; i++, dval(d) *= 10.) {
L = (Long)(dval(d) / ds);
dval(d) -= L*ds;
@ -448,7 +439,7 @@ __dtoa
if (dval(d) < 0) {
L--;
dval(d) += ds;
}
}
#endif
*s++ = '0' + (int)L;
if (!dval(d)) {
@ -456,14 +447,14 @@ __dtoa
inexact = 0;
#endif
break;
}
}
if (i == ilim) {
#ifdef Honor_FLT_ROUNDS
if (mode > 1)
switch(rounding) {
switch(rounding) {
case 0: goto ret1;
case 2: goto bump_up;
}
}
#endif
dval(d) += dval(d);
if (dval(d) > ds || (dval(d) == ds && L & 1)) {
@ -473,14 +464,14 @@ __dtoa
k++;
*s = '0';
break;
}
}
++*s++;
}
break;
}
break;
}
goto ret1;
}
goto ret1;
}
m2 = b2;
m5 = b5;
@ -498,13 +489,13 @@ __dtoa
b2 += i;
s2 += i;
mhi = i2b(1);
}
}
if (m2 > 0 && s2 > 0) {
i = m2 < s2 ? m2 : s2;
b2 -= i;
m2 -= i;
s2 -= i;
}
}
if (b5 > 0) {
if (leftright) {
if (m5 > 0) {
@ -512,13 +503,13 @@ __dtoa
b1 = mult(mhi, b);
Bfree(b);
b = b1;
}
}
if (( j = b5 - m5 )!=0)
b = pow5mult(b, j);
}
}
else
b = pow5mult(b, b5);
}
}
S = i2b(1);
if (s5 > 0)
S = pow5mult(S, s5);
@ -540,8 +531,8 @@ __dtoa
b2 += Log2P;
s2 += Log2P;
spec_case = 1;
}
}
}
/* Arrange for convenient computation of quotients:
* shift left if necessary so divisor has 4 leading 0 bits.
@ -562,13 +553,13 @@ __dtoa
b2 += i;
m2 += i;
s2 += i;
}
}
else if (i < 4) {
i += 28;
b2 += i;
m2 += i;
s2 += i;
}
}
if (b2 > 0)
b = lshift(b, b2);
if (s2 > 0)
@ -580,20 +571,20 @@ __dtoa
if (leftright)
mhi = multadd(mhi, 10, 0);
ilim = ilim1;
}
}
}
if (ilim <= 0 && (mode == 3 || mode == 5)) {
if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
/* no digits, fcvt style */
no_digits:
k = -1 - ndigits;
goto ret;
}
}
one_digit:
*s++ = '1';
k++;
goto ret;
}
}
if (leftright) {
if (m2 > 0)
mhi = lshift(mhi, m2);
@ -607,7 +598,7 @@ __dtoa
mhi = Balloc(mhi->k);
Bcopy(mhi, mlo);
mhi = lshift(mhi, Log2P);
}
}
for(i = 1;;i++) {
dig = quorem(b,S) + '0';
@ -634,7 +625,7 @@ __dtoa
#endif
*s++ = dig;
goto ret;
}
}
#endif
if (j < 0 || (j == 0 && mode != 1
#ifndef ROUND_BIASED
@ -646,13 +637,13 @@ __dtoa
inexact = 0;
#endif
goto accept_dig;
}
}
#ifdef Honor_FLT_ROUNDS
if (mode > 1)
switch(rounding) {
case 0: goto accept_dig;
case 2: goto keep_dig;
}
}
#endif /*Honor_FLT_ROUNDS*/
if (j1 > 0) {
b = lshift(b, 1);
@ -660,11 +651,11 @@ __dtoa
if ((j1 > 0 || (j1 == 0 && dig & 1))
&& dig++ == '9')
goto round_9_up;
}
}
accept_dig:
*s++ = dig;
goto ret;
}
}
if (j1 > 0) {
#ifdef Honor_FLT_ROUNDS
if (!rounding)
@ -674,10 +665,10 @@ __dtoa
round_9_up:
*s++ = '9';
goto roundoff;
}
}
*s++ = dig + 1;
goto ret;
}
}
#ifdef Honor_FLT_ROUNDS
keep_dig:
#endif
@ -690,9 +681,9 @@ __dtoa
else {
mlo = multadd(mlo, 10, 0);
mhi = multadd(mhi, 10, 0);
}
}
}
}
else
for(i = 1;; i++) {
*s++ = dig = quorem(b,S) + '0';
@ -701,11 +692,11 @@ __dtoa
inexact = 0;
#endif
goto ret;
}
}
if (i >= ilim)
break;
b = multadd(b, 10, 0);
}
}
/* Round off last digit */
@ -713,7 +704,7 @@ __dtoa
switch(rounding) {
case 0: goto trimzeros;
case 2: goto roundoff;
}
}
#endif
b = lshift(b, 1);
j = cmp(b, S);
@ -724,21 +715,21 @@ __dtoa
k++;
*s++ = '1';
goto ret;
}
}
++*s++;
}
}
else {
// trimzeros:
while(*--s == '0');
s++;
}
}
ret:
Bfree(S);
if (mhi) {
if (mlo && mlo != mhi)
Bfree(mlo);
Bfree(mhi);
}
}
ret1:
#ifdef SET_INEXACT
if (inexact) {
@ -746,8 +737,8 @@ __dtoa
word0(d) = Exp_1 + (70 << Exp_shift);
word1(d) = 0;
dval(d) += 1.;
}
}
}
else if (!oldinexact)
clear_inexact();
#endif
@ -757,7 +748,7 @@ __dtoa
if (rve)
*rve = s;
return s0;
}
}
#ifndef __HAVE_GCC44
#undef d
#endif

View File

@ -35,12 +35,7 @@ THIS SOFTWARE.
#include "locale.h"
#endif
char *
#ifdef KR_headers
__g__fmt(b, s, se, decpt, sign) char *b; char *s; char *se; int decpt; ULong sign;
#else
__g__fmt(char *b, char *s, char *se, int decpt, ULong sign)
#endif
char *__g__fmt (char *b, char *s, char *se, int decpt, ULong sign)
{
int i, j, k;
char *s0 = s;
@ -57,13 +52,13 @@ __g__fmt(char *b, char *s, char *se, int decpt, ULong sign)
*b++ = decimalpoint;
while((*b = *s++) !=0)
b++;
}
}
*b++ = 'e';
/* sprintf(b, "%+.2d", decpt - 1); */
if (--decpt < 0) {
*b++ = '-';
decpt = -decpt;
}
}
else
*b++ = '+';
for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10){}
@ -74,26 +69,26 @@ __g__fmt(char *b, char *s, char *se, int decpt, ULong sign)
break;
decpt -= i*k;
decpt *= 10;
}
*b = 0;
}
*b = 0;
}
else if (decpt <= 0) {
*b++ = decimalpoint;
for(; decpt < 0; decpt++)
*b++ = '0';
while((*b = *s++) !=0)
b++;
}
}
else {
while((*b = *s++) !=0) {
b++;
if (--decpt == 0 && *s)
*b++ = decimalpoint;
}
}
for(; decpt > 0; decpt--)
*b++ = '0';
*b = 0;
}
}
__freedtoa(s0);
return b;
}
}

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
char*
#ifdef KR_headers
__g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; unsigned bufsize;
#else
__g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
#endif
char *__g_dfmt (char *buf, double *d, int ndig, unsigned bufsize)
{
static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 };
char *b, *s, *se;
@ -54,12 +49,12 @@ __g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
/* Infinity or NaN */
if (L[_0] & 0xfffff || L[_1]) {
return strcp(buf, "NaN");
}
}
b = buf;
if (sign)
*b++ = '-';
return strcp(b, "Infinity");
}
}
if (L[_1] == 0 && (L[_0] ^ sign) == 0 /*d == 0.*/) {
b = buf;
#ifndef IGNORE_ZERO_SIGN
@ -69,7 +64,7 @@ __g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
*b++ = '0';
*b = 0;
return b;
}
}
bits[0] = L[_1];
bits[1] = L[_0] & 0xfffff;
if ( (ex = (L[_0] >> 20) & 0x7ff) !=0)
@ -82,8 +77,8 @@ __g_dfmt(char *buf, double *d, int ndig, unsigned bufsize)
if (bufsize < 25)
return 0;
mode = 0;
}
}
i = STRTOG_Normal;
s = __gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
return __g__fmt(buf, s, se, decpt, sign);
}
}

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
char*
#ifdef KR_headers
__g_ffmt(buf, f, ndig, bufsize) char *buf; float *f; int ndig; unsigned bufsize;
#else
__g_ffmt(char *buf, float *f, int ndig, unsigned bufsize)
#endif
char *__g_ffmt (char *buf, float *f, int ndig, unsigned bufsize)
{
static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, 0 };
char *b, *s, *se;
@ -59,7 +54,7 @@ __g_ffmt(char *buf, float *f, int ndig, unsigned bufsize)
if (sign)
*b++ = '-';
return strcp(b, "Infinity");
}
}
if (*f == 0.) {
b = buf;
#ifndef IGNORE_ZERO_SIGN
@ -69,7 +64,7 @@ __g_ffmt(char *buf, float *f, int ndig, unsigned bufsize)
*b++ = '0';
*b = 0;
return b;
}
}
bits[0] = L[0] & 0x7fffff;
if ( (ex = (L[0] >> 23) & 0xff) !=0)
bits[0] |= 0x800000;
@ -81,8 +76,8 @@ __g_ffmt(char *buf, float *f, int ndig, unsigned bufsize)
if (bufsize < 16)
return 0;
mode = 0;
}
}
i = STRTOG_Normal;
s = __gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
return __g__fmt(buf, s, se, decpt, sign);
}
}

View File

@ -51,12 +51,7 @@ THIS SOFTWARE.
#define _4 0
#endif
char*
#ifdef KR_headers
__g_xfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; unsigned bufsize;
#else
__g_xfmt(char *buf, void *V, int ndig, unsigned bufsize)
#endif
char *__g_xfmt (char *buf, void *V, int ndig, unsigned bufsize)
{
static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };
char *b, *s, *se;
@ -78,29 +73,24 @@ __g_xfmt(char *buf, void *V, int ndig, unsigned bufsize)
bits[1] = (L[_1] << 16) | L[_2];
bits[0] = (L[_3] << 16) | L[_4];
if (fptype & FP_NAN) /* NaN or Inf */
{
if (fptype & FP_NORMAL)
{
b = buf;
*b++ = sign ? '-': '+';
strncpy (b, "Infinity", ndig ? ndig : 8);
if (fptype & FP_NAN) { /* NaN or Inf */
if (fptype & FP_NORMAL) {
b = buf;
*b++ = sign ? '-': '+';
strncpy (b, "Infinity", ndig ? ndig : 8);
return (buf + strlen (buf));
}
strncpy (buf, "NaN", ndig ? ndig : 3);
return (buf + strlen (buf));
}
strncpy (buf, "NaN", ndig ? ndig : 3);
return (buf + strlen (buf));
}
else if (fptype & FP_NORMAL) /* Normal or subnormal */
{
if (fptype & FP_ZERO)
{
i = STRTOG_Denormal;
ex = 1;
}
else
i = STRTOG_Normal;
}
}
else if (fptype & FP_NORMAL) { /* Normal or subnormal */
if (fptype & FP_ZERO) {
i = STRTOG_Denormal;
ex = 1;
}
else
i = STRTOG_Normal;
}
else {
i = STRTOG_Zero;
b = buf;
@ -111,7 +101,7 @@ __g_xfmt(char *buf, void *V, int ndig, unsigned bufsize)
*b++ = '0';
*b = 0;
return b;
}
}
ex -= 0x3fff + 63;
mode = 2;
@ -119,7 +109,7 @@ __g_xfmt(char *buf, void *V, int ndig, unsigned bufsize)
if (bufsize < 32)
return 0;
mode = 0;
}
}
s = __gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
return __g__fmt(buf, s, se, decpt, sign);
}
}

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
static Bigint *
#ifdef KR_headers
bitstob(bits, nbits, bbits) ULong *bits; int nbits; int *bbits;
#else
bitstob(ULong *bits, int nbits, int *bbits)
#endif
static Bigint *bitstob (ULong *bits, int nbits, int *bbits)
{
int i, k;
Bigint *b;
@ -108,15 +103,8 @@ bitstob(ULong *bits, int nbits, int *bbits)
* calculation.
*/
char *
__gdtoa
#ifdef KR_headers
(fpi, be, bits, kindp, mode, ndigits, decpt, rve)
FPI *fpi; int be; ULong *bits;
int *kindp, mode, ndigits, *decpt; char **rve;
#else
(FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits, int *decpt, char **rve)
#endif
char *__gdtoa (FPI *fpi, int be, ULong *bits, int *kindp, int mode, int ndigits,
int *decpt, char **rve)
{
/* Arguments ndigits and decpt are similar to the second and third
arguments of ecvt and fcvt; trailing zeros are suppressed from
@ -187,20 +175,20 @@ __gdtoa
return nrv_alloc("NaN", rve, 3);
default:
return 0;
}
}
b = bitstob(bits, nbits = fpi->nbits, &bbits);
be0 = be;
if ( (i = trailz(b)) !=0) {
rshift(b, i);
be += i;
bbits -= i;
}
}
if (!b->wds) {
Bfree(b);
ret_zero:
*decpt = 1;
return nrv_alloc("0", rve, 1);
}
}
dval(d) = b2d(b, &i);
i = be + bbits - 1;
@ -260,33 +248,33 @@ __gdtoa
if (dval(d) < tens[k])
k--;
k_check = 0;
}
}
j = bbits - i - 1;
if (j >= 0) {
b2 = 0;
s2 = j;
}
}
else {
b2 = -j;
s2 = 0;
}
}
if (k >= 0) {
b5 = 0;
s5 = k;
s2 += k;
}
}
else {
b2 -= k;
b5 = -k;
s5 = 0;
}
}
if (mode < 0 || mode > 9)
mode = 0;
try_quick = 1;
if (mode > 5) {
mode -= 4;
try_quick = 0;
}
}
leftright = 1;
switch(mode) {
case 0:
@ -312,7 +300,7 @@ __gdtoa
ilim1 = i - 1;
if (i <= 0)
i = 1;
}
}
s = s0 = rv_alloc(i);
if ( (rdir = fpi->rounding - 1) !=0) {
@ -320,7 +308,7 @@ __gdtoa
rdir = 2;
if (kind & STRTOG_Neg)
rdir = 3 - rdir;
}
}
/* Now rdir = 0 ==> round near, 1 ==> round up, 2 ==> round down. */
@ -349,13 +337,13 @@ __gdtoa
j &= Bletch - 1;
dval(d) /= bigtens[n_bigtens-1];
ieps++;
}
}
for(; j; j >>= 1, i++)
if (j & 1) {
ieps++;
ds *= bigtens[i];
}
}
}
}
else {
ds = 1.;
if ( (j1 = -k) !=0) {
@ -364,9 +352,9 @@ __gdtoa
if (j & 1) {
ieps++;
dval(d) *= bigtens[i];
}
}
}
}
}
if (k_check && dval(d) < 1. && ilim > 0) {
if (ilim1 <= 0)
goto fast_failed;
@ -374,7 +362,7 @@ __gdtoa
k--;
dval(d) *= 10.;
ieps++;
}
}
dval(eps) = ieps*dval(d) + 7.;
word0(eps) -= (P-1)*Exp_msk1;
if (ilim == 0) {
@ -385,7 +373,7 @@ __gdtoa
if (dval(d) < -dval(eps))
goto no_digits;
goto fast_failed;
}
}
#ifndef No_leftright
if (leftright) {
/* Use Steele & White method of only
@ -400,15 +388,15 @@ __gdtoa
if (dval(d))
inex = STRTOG_Inexlo;
goto ret1;
}
}
if (ds - dval(d) < dval(eps))
goto bump_up;
if (++i >= ilim)
break;
dval(eps) *= 10.;
dval(d) *= 10.;
}
}
}
else {
#endif
/* Generate ilim digits, then fix them up. */
@ -427,19 +415,19 @@ __gdtoa
if (dval(d))
inex = STRTOG_Inexlo;
goto ret1;
}
break;
}
break;
}
#ifndef No_leftright
}
#ifndef No_leftright
}
#endif
fast_failed:
s = s0;
dval(d) = d2;
k = k0;
ilim = ilim0;
}
}
/* Do we have a "small" integer? */
@ -451,7 +439,7 @@ __gdtoa
if (ilim < 0 || dval(d) <= 5*ds)
goto no_digits;
goto one_digit;
}
}
for(i = 1;; i++, dval(d) *= 10.) {
L = dval(d) / ds;
dval(d) -= L*ds;
@ -460,7 +448,7 @@ __gdtoa
if (dval(d) < 0) {
L--;
dval(d) += ds;
}
}
#endif
*s++ = '0' + (int)L;
if (dval(d) == 0.)
@ -471,7 +459,7 @@ __gdtoa
goto bump_up;
inex = STRTOG_Inexlo;
goto ret1;
}
}
dval(d) += dval(d);
if (dval(d) > ds || (dval(d) == ds && L & 1)) {
bump_up:
@ -483,14 +471,14 @@ __gdtoa
break;
}
++*s++;
}
}
else
inex = STRTOG_Inexlo;
break;
}
}
goto ret1;
}
goto ret1;
}
m2 = b2;
m5 = b5;
@ -501,7 +489,7 @@ __gdtoa
if (be - i++ < fpi->emin)
/* denormal */
i = be - fpi->emin + 1;
}
}
else {
j = ilim - 1;
if (m5 >= j)
@ -510,22 +498,22 @@ __gdtoa
s5 += j -= m5;
b5 += j;
m5 = 0;
}
}
if ((i = ilim) < 0) {
m2 -= i;
i = 0;
}
}
}
b2 += i;
s2 += i;
mhi = i2b(1);
}
}
if (m2 > 0 && s2 > 0) {
i = m2 < s2 ? m2 : s2;
b2 -= i;
m2 -= i;
s2 -= i;
}
}
if (b5 > 0) {
if (leftright) {
if (m5 > 0) {
@ -533,13 +521,13 @@ __gdtoa
b1 = mult(mhi, b);
Bfree(b);
b = b1;
}
}
if ( (j = b5 - m5) !=0)
b = pow5mult(b, j);
}
}
else
b = pow5mult(b, b5);
}
}
S = i2b(1);
if (s5 > 0)
S = pow5mult(S, s5);
@ -553,8 +541,8 @@ __gdtoa
b2++;
s2++;
spec_case = 1;
}
}
}
/* Arrange for convenient computation of quotients:
* shift left if necessary so divisor has 4 leading 0 bits.
@ -575,13 +563,13 @@ __gdtoa
b2 += i;
m2 += i;
s2 += i;
}
}
else if (i < 4) {
i += 28;
b2 += i;
m2 += i;
s2 += i;
}
}
if (b2 > 0)
b = lshift(b, b2);
if (s2 > 0)
@ -593,8 +581,8 @@ __gdtoa
if (leftright)
mhi = multadd(mhi, 10, 0);
ilim = ilim1;
}
}
}
if (ilim <= 0 && mode > 2) {
if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
/* no digits, fcvt style */
@ -602,13 +590,13 @@ __gdtoa
k = -1 - ndigits;
inex = STRTOG_Inexlo;
goto ret;
}
}
one_digit:
inex = STRTOG_Inexhi;
*s++ = '1';
k++;
goto ret;
}
}
if (leftright) {
if (m2 > 0)
mhi = lshift(mhi, m2);
@ -622,7 +610,7 @@ __gdtoa
mhi = Balloc(mhi->k);
Bcopy(mhi, mlo);
mhi = lshift(mhi, 1);
}
}
for(i = 1;;i++) {
dig = quorem(b,S) + '0';
@ -640,14 +628,14 @@ __gdtoa
if (j <= 0) {
if (b->wds > 1 || b->x[0])
inex = STRTOG_Inexlo;
}
}
else {
dig++;
inex = STRTOG_Inexhi;
}
}
*s++ = dig;
goto ret;
}
}
#endif
if (j < 0 || (j == 0 && !mode
#ifndef ROUND_BIASED
@ -658,7 +646,7 @@ __gdtoa
if (rdir == 2) {
inex = STRTOG_Inexlo;
goto accept;
}
}
while (cmp(S,mhi) > 0) {
*s++ = dig;
mhi1 = multadd(mhi, 10, 0);
@ -667,12 +655,12 @@ __gdtoa
mhi = mhi1;
b = multadd(b, 10, 0);
dig = quorem(b,S) + '0';
}
}
if (dig++ == '9')
goto round_9_up;
inex = STRTOG_Inexhi;
goto accept;
}
}
if (j1 > 0) {
b = lshift(b, 1);
j1 = cmp(b, S);
@ -680,24 +668,24 @@ __gdtoa
&& dig++ == '9')
goto round_9_up;
inex = STRTOG_Inexhi;
}
}
if (b->wds > 1 || b->x[0])
inex = STRTOG_Inexlo;
accept:
*s++ = dig;
goto ret;
}
}
if (j1 > 0 && rdir != 2) {
if (dig == '9') { /* possible if i == 1 */
round_9_up:
*s++ = '9';
inex = STRTOG_Inexhi;
goto roundoff;
}
}
inex = STRTOG_Inexhi;
*s++ = dig + 1;
goto ret;
}
}
*s++ = dig;
if (i == ilim)
break;
@ -707,16 +695,16 @@ __gdtoa
else {
mlo = multadd(mlo, 10, 0);
mhi = multadd(mhi, 10, 0);
}
}
}
}
else
for(i = 1;; i++) {
*s++ = dig = quorem(b,S) + '0';
if (i >= ilim)
break;
b = multadd(b, 10, 0);
}
}
/* Round off last digit */
@ -724,7 +712,7 @@ __gdtoa
if (rdir == 2 || (b->wds <= 1 && !b->x[0]))
goto chopzeros;
goto roundoff;
}
}
b = lshift(b, 1);
j = cmp(b, S);
if (j > 0 || (j == 0 && dig & 1)) {
@ -737,21 +725,21 @@ __gdtoa
goto ret;
}
++*s++;
}
}
else {
chopzeros:
if (b->wds > 1 || b->x[0])
inex = STRTOG_Inexlo;
while(*--s == '0'){}
s++;
}
}
ret:
Bfree(S);
if (mhi) {
if (mlo && mlo != mhi)
Bfree(mlo);
Bfree(mhi);
}
}
ret1:
Bfree(b);
*s = 0;
@ -760,4 +748,4 @@ __gdtoa
*rve = s;
*kindp |= inex;
return s0;
}
}

View File

@ -47,25 +47,7 @@ typedef unsigned Long ULong;
typedef unsigned short UShort;
#endif
#ifndef ANSI
#ifdef KR_headers
#define ANSI(x) ()
#define Void /*nothing*/
#else
#define ANSI(x) x
#define Void void
#endif
#endif /* ANSI */
#ifndef CONST
#ifdef KR_headers
#define CONST /* blank */
#else
#define CONST const
#endif
#endif /* CONST */
enum { /* return values from strtodg */
enum { /* return values from strtodg */
STRTOG_Zero = 0,
STRTOG_Normal = 1,
STRTOG_Denormal = 2,
@ -85,41 +67,41 @@ typedef unsigned short UShort;
STRTOG_Overflow = 0x80
};
typedef struct
typedef struct
FPI {
int nbits;
int emin;
int emax;
int rounding;
int sudden_underflow;
} FPI;
} FPI;
enum { /* FPI.rounding values: same as FLT_ROUNDS */
FPI_Round_zero = 0,
FPI_Round_near = 1,
FPI_Round_up = 2,
FPI_Round_down = 3
};
};
#ifdef __cplusplus
extern "C" {
#endif
extern char* __dtoa ANSI((double d, int mode, int ndigits, int *decpt,
int *sign, char **rve));
extern char* __gdtoa ANSI((FPI *fpi, int be, ULong *bits, int *kindp,
int mode, int ndigits, int *decpt, char **rve));
extern void __freedtoa ANSI((char*));
extern char* __dtoa (double d, int mode, int ndigits, int *decpt,
int *sign, char **rve);
extern char* __gdtoa (FPI *fpi, int be, ULong *bits, int *kindp,
int mode, int ndigits, int *decpt, char **rve));
extern void __freedtoa (char *);
extern int __strtodg ANSI((CONST char*, char**, FPI*, Long*, ULong*));
extern float __strtof ANSI((CONST char *, char **));
extern double __strtod ANSI((CONST char *, char **));
extern long double strtold ANSI((CONST char *, char **));
extern int __strtodg (const char *, char **, FPI *, Long *, ULong *);
extern float __strtof (const char *, char **);
extern double __strtod (const char *, char **);
extern long double strtold (const char *, char **);
extern char* __g__fmt ANSI((char *, char *, char *e, int, ULong));
extern char* __g_dfmt ANSI((char*, double*, int, unsigned));
extern char* __g_ffmt ANSI((char*, float*, int, unsigned));
extern char* __g_xfmt ANSI((char*, void*, int, unsigned));
extern char* __g__fmt (char*, char*, char*, int, ULong);
extern char* __g_dfmt (char*, double*, int, unsigned);
extern char* __g_ffmt (char*, float*, int, unsigned);
extern char* __g_xfmt (char*, void*, int, unsigned);
#ifdef __cplusplus
}

View File

@ -182,14 +182,8 @@ THIS SOFTWARE.
#include <stdlib.h>
#include <string.h>
#ifdef KR_headers
#define Char char
#else
#define Char void
#endif
#ifdef MALLOC
extern Char *MALLOC ANSI((size_t));
extern void *MALLOC (size_t);
#else
#define MALLOC malloc
#endif
@ -423,11 +417,7 @@ typedef union _dbl_union { double d; ULong L[2]; } dbl_union;
#ifdef RND_PRODQUOT
#define rounded_product(a,b) a = rnd_prod(a, b)
#define rounded_quotient(a,b) a = rnd_quot(a, b)
#ifdef KR_headers
extern double rnd_prod(), rnd_quot();
#else
extern double rnd_prod(double, double), rnd_quot(double, double);
#endif
#else
#define rounded_product(a,b) a *= b
#define rounded_quotient(a,b) a /= b
@ -481,20 +471,19 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
#define Kmax 15
#define Bigint __Bigint
struct
struct
Bigint {
struct Bigint *next;
int k, maxwds, sign, wds;
ULong x[1];
};
typedef struct Bigint Bigint;
};
typedef struct Bigint Bigint;
#ifdef NO_STRING_H
#ifdef DECLARE_SIZE_T
typedef unsigned int size_t;
#endif
extern void memcpy_D2A ANSI((void*, const void*, size_t));
extern void memcpy_D2A (void *, const void *, size_t);
#define Bcopy(x,y) memcpy_D2A(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
#else /* !NO_STRING_H */
#define Bcopy(x,y) memcpy(&x->sign,&y->sign,y->wds*sizeof(ULong) + 2*sizeof(int))
@ -504,15 +493,15 @@ extern void memcpy_D2A ANSI((void*, const void*, size_t));
static inline int
__lo0bits_D2A (ULong *y)
{
int ret = __builtin_ctz(*y);
*y = *y >> ret;
return ret;
int ret = __builtin_ctz(*y);
*y = *y >> ret;
return ret;
}
static inline int
__hi0bits_D2A (ULong y)
{
return __builtin_clz(y);
return __builtin_clz(y);
}
#endif
@ -563,48 +552,48 @@ __hi0bits_D2A (ULong y)
#define trailz __trailz_D2A
#define ulp __ulp_D2A
extern char *dtoa_result;
extern CONST double bigtens[], tens[], tinytens[];
extern unsigned char hexdig[];
extern char *dtoa_result;
extern const double bigtens[], tens[], tinytens[];
extern unsigned char hexdig[];
extern Bigint *Balloc ANSI((int));
extern void Bfree ANSI((Bigint*));
extern void ULtof ANSI((ULong*, ULong*, Long, int));
extern void ULtod ANSI((ULong*, ULong*, Long, int));
extern void ULtodd ANSI((ULong*, ULong*, Long, int));
extern void ULtoQ ANSI((ULong*, ULong*, Long, int));
extern void ULtox ANSI((UShort*, ULong*, Long, int));
extern void ULtoxL ANSI((ULong*, ULong*, Long, int));
extern ULong any_on ANSI((Bigint*, int));
extern double b2d ANSI((Bigint*, int*));
extern int cmp ANSI((Bigint*, Bigint*));
extern void copybits ANSI((ULong*, int, Bigint*));
extern Bigint *d2b ANSI((double, int*, int*));
extern int decrement ANSI((Bigint*));
extern Bigint *diff ANSI((Bigint*, Bigint*));
extern int gethex ANSI((CONST char**, FPI*, Long*, Bigint**, int));
extern void hexdig_init_D2A(Void);
extern int hexnan ANSI((CONST char**, FPI*, ULong*));
extern int hi0bits_D2A ANSI((ULong));
extern Bigint *i2b ANSI((int));
extern Bigint *increment ANSI((Bigint*));
extern int lo0bits ANSI((ULong*));
extern Bigint *lshift ANSI((Bigint*, int));
extern int match ANSI((CONST char**, char*));
extern Bigint *mult ANSI((Bigint*, Bigint*));
extern Bigint *multadd ANSI((Bigint*, int, int));
extern char *nrv_alloc ANSI((char*, char **, int));
extern Bigint *pow5mult ANSI((Bigint*, int));
extern int quorem ANSI((Bigint*, Bigint*));
extern double ratio ANSI((Bigint*, Bigint*));
extern void rshift ANSI((Bigint*, int));
extern char *rv_alloc ANSI((int));
extern Bigint *s2b ANSI((CONST char*, int, int, ULong));
extern Bigint *set_ones ANSI((Bigint*, int));
extern char *strcp ANSI((char*, const char*));
extern Bigint *sum ANSI((Bigint*, Bigint*));
extern int trailz ANSI((Bigint*));
extern double ulp ANSI((double));
extern Bigint *Balloc (int);
extern void Bfree (Bigint*);
extern void ULtof (ULong*, ULong*, Long, int);
extern void ULtod (ULong*, ULong*, Long, int);
extern void ULtodd (ULong*, ULong*, Long, int);
extern void ULtoQ (ULong*, ULong*, Long, int);
extern void ULtox (UShort*, ULong*, Long, int);
extern void ULtoxL (ULong*, ULong*, Long, int);
extern ULong any_on (Bigint*, int);
extern double b2d (Bigint*, int*);
extern int cmp (Bigint*, Bigint*);
extern void copybits (ULong*, int, Bigint*);
extern Bigint *d2b (double, int*, int*);
extern int decrement (Bigint*);
extern Bigint *diff (Bigint*, Bigint*);
extern int gethex (const char**, FPI*, Long*, Bigint**, int);
extern void hexdig_init_D2A(void);
extern int hexnan (const char**, FPI*, ULong*);
extern int hi0bits_D2A (ULong);
extern Bigint *i2b (int);
extern Bigint *increment (Bigint*);
extern int lo0bits (ULong*);
extern Bigint *lshift (Bigint*, int);
extern int match (const char**, char*);
extern Bigint *mult (Bigint*, Bigint*);
extern Bigint *multadd (Bigint*, int, int);
extern char *nrv_alloc (char*, char **, int);
extern Bigint *pow5mult (Bigint*, int);
extern int quorem (Bigint*, Bigint*);
extern double ratio (Bigint*, Bigint*);
extern void rshift (Bigint*, int);
extern char *rv_alloc (int);
extern Bigint *s2b (const char*, int, int, ULong);
extern Bigint *set_ones (Bigint*, int);
extern char *strcp (char*, const char*);
extern Bigint *sum (Bigint*, Bigint*);
extern int trailz (Bigint*);
extern double ulp (double);
#ifdef __cplusplus
}

View File

@ -35,16 +35,10 @@ THIS SOFTWARE.
#include "locale.h"
#endif
int
#ifdef KR_headers
gethex(sp, fpi, exp, bp, sign)
CONST char **sp; FPI *fpi; Long *exp; Bigint **bp; int sign;
#else
gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
#endif
int gethex (const char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
{
Bigint *b;
CONST unsigned char *decpt, *s0, *s, *s1;
const unsigned char *decpt, *s0, *s, *s1;
int esign, havedig, irv, k, n, nbits, up, zret;
ULong L, lostbits, *x;
Long e, e1;
@ -57,7 +51,7 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
if (!hexdig['0'])
hexdig_init_D2A();
havedig = 0;
s0 = *(CONST unsigned char **)sp + 2;
s0 = *(const unsigned char **)sp + 2;
while(s0[havedig] == '0')
havedig++;
s0 += havedig;
@ -78,14 +72,14 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
zret = 0;
havedig = 1;
s0 = s;
}
}
while(hexdig[*s])
s++;
if (*s == decimalpoint && !decpt) {
decpt = ++s;
while(hexdig[*s])
s++;
}
}
if (decpt)
e = -(((Long)(s-decpt)) << 2);
pcheck:
@ -100,18 +94,18 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
/* no break */
case '+':
s++;
}
}
if ((n = hexdig[*s]) == 0 || n > 0x19) {
s = s1;
break;
}
}
e1 = n - 0x10;
while((n = hexdig[*++s]) !=0 && n <= 0x19)
e1 = 10*e1 + n - 0x10;
if (esign)
e1 = -e1;
e += e1;
}
}
*sp = (char*)s;
if (zret)
return havedig ? STRTOG_Zero : STRTOG_NoNumber;
@ -129,10 +123,10 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
*x++ = L;
L = 0;
n = 0;
}
}
L |= (hexdig[*s1] & 0x0f) << n;
n += 4;
}
}
*x++ = L;
b->wds = n = x - b->x;
n = 32*n - hi0bits(L);
@ -148,23 +142,23 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
lostbits = 2;
if (k > 1 && any_on(b,k-1))
lostbits = 3;
}
}
}
rshift(b, n);
e += n;
}
}
else if (n < nbits) {
n = nbits - n;
b = lshift(b, n);
e -= n;
x = b->x;
}
}
if (e > fpi->emax) {
ovfl:
Bfree(b);
*bp = 0;
return STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
}
}
irv = STRTOG_Normal;
if (e < fpi->emin) {
irv = STRTOG_Denormal;
@ -187,12 +181,12 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
*bp = b;
return STRTOG_Denormal | STRTOG_Inexhi
| STRTOG_Underflow;
}
}
}
}
Bfree(b);
*bp = 0;
return STRTOG_Zero | STRTOG_Inexlo | STRTOG_Underflow;
}
}
k = n - 1;
if (lostbits)
lostbits = 1;
@ -203,7 +197,7 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
nbits -= n;
rshift(b,n);
e = fpi->emin;
}
}
if (lostbits) {
up = 0;
switch(fpi->rounding) {
@ -219,7 +213,7 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
break;
case FPI_Round_down:
up = sign;
}
}
if (up) {
k = b->wds;
b = increment(b);
@ -228,20 +222,20 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
if (nbits == fpi->nbits - 1
&& x[nbits >> kshift] & 1 << (nbits & kmask))
irv = STRTOG_Normal;
}
}
else if (b->wds > k
|| ((n = nbits & kmask) !=0
&& hi0bits(x[k-1]) < 32-n)) {
rshift(b,1);
if (++e > fpi->emax)
goto ovfl;
}
irv |= STRTOG_Inexhi;
}
irv |= STRTOG_Inexhi;
}
else
irv |= STRTOG_Inexlo;
}
}
*bp = b;
*exp = e;
return irv;
}
}

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
void
#ifdef KR_headers
rshift(b, k) Bigint *b; int k;
#else
rshift(Bigint *b, int k)
#endif
void rshift (Bigint *b, int k)
{
ULong *x, *x1, *xe, y;
int n;
@ -52,24 +47,19 @@ rshift(Bigint *b, int k)
while(x < xe) {
*x1++ = (y | (*x << n)) & ALL_ON;
y = *x++ >> k;
}
}
if ((*x1 = y) !=0)
x1++;
}
}
else
while(x < xe)
*x1++ = *x++;
}
}
if ((b->wds = x1 - b->x) == 0)
b->x[0] = 0;
}
}
int
#ifdef KR_headers
trailz(b) Bigint *b;
#else
trailz(Bigint *b)
#endif
int trailz (Bigint *b)
{
ULong L, *x, *xe;
int n = 0;
@ -81,6 +71,6 @@ trailz(Bigint *b)
if (x < xe) {
L = *x;
n += lo0bits(&L);
}
return n;
}
return n;
}

View File

@ -31,25 +31,19 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
unsigned char hexdig[256];
unsigned char hexdig[256];
static void
#ifdef KR_headers
htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc;
#else
htinit(unsigned char *h, unsigned char *s, int inc)
#endif
static void htinit (unsigned char *h, unsigned char *s, int inc)
{
int i, j;
for(i = 0; (j = s[i]) !=0; i++)
h[j] = i + inc;
}
}
void
hexdig_init_D2A(Void)
void hexdig_init_D2A (void)
{
#define USC (unsigned char *)
htinit(hexdig, USC "0123456789", 0x10);
htinit(hexdig, USC "abcdef", 0x10 + 10);
htinit(hexdig, USC "ABCDEF", 0x10 + 10);
}
}

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
static void
#ifdef KR_headers
L_shift(x, x1, i) ULong *x; ULong *x1; int i;
#else
L_shift(ULong *x, ULong *x1, int i)
#endif
static void L_shift (ULong *x, ULong *x1, int i)
{
int j;
@ -46,19 +41,13 @@ L_shift(ULong *x, ULong *x1, int i)
do {
*x |= x[1] << j;
x[1] >>= i;
} while(++x < x1);
}
} while(++x < x1);
}
int
#ifdef KR_headers
hexnan(sp, fpi, x0)
CONST char **sp; FPI *fpi; ULong *x0;
#else
hexnan( CONST char **sp, FPI *fpi, ULong *x0)
#endif
int hexnan (const char **sp, FPI *fpi, ULong *x0)
{
ULong c, h, *x, *x1, *xe;
CONST char *s;
const char *s;
int havedig, hd0, i, nbits;
if (!hexdig['0'])
@ -71,7 +60,7 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
x1 = xe = x;
havedig = hd0 = i = 0;
s = *sp;
while((c = *(CONST unsigned char*)++s)) {
while((c = *(const unsigned char*)++s)) {
if (!(h = hexdig[c])) {
if (c <= ' ') {
if (hd0 < havedig) {
@ -80,29 +69,29 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
if (x <= x0) {
i = 8;
continue;
}
}
hd0 = havedig;
*--x = 0;
x1 = x;
i = 0;
}
continue;
}
continue;
}
if (/*(*/ c == ')' && havedig) {
*sp = s + 1;
break;
}
return STRTOG_NaN;
}
return STRTOG_NaN;
}
havedig++;
if (++i > 8) {
if (x <= x0)
continue;
i = 1;
*--x = 0;
}
*x = (*x << 4) | (h & 0xf);
}
*x = (*x << 4) | (h & 0xf);
}
if (!havedig)
return STRTOG_NaN;
if (x < x1 && i < 8)
@ -113,19 +102,19 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
while(x <= xe);
do *x1++ = 0;
while(x1 <= xe);
}
}
else {
/* truncate high-order word if necessary */
if ( (i = nbits & (ULbits-1)) !=0)
*xe &= ((ULong)0xffffffff) >> (ULbits - i);
}
}
for(x1 = xe;; --x1) {
if (*x1 != 0)
break;
if (x1 == x0) {
*x1 = 1;
break;
}
}
return STRTOG_NaNbits;
}
return STRTOG_NaNbits;
}

View File

@ -55,54 +55,48 @@ static long dtoa_CS_init = 0;
1 = initializing
2 = initialized
3 = deleted
*/
static void dtoa_lock_cleanup()
*/
static void dtoa_lock_cleanup (void)
{
long last_CS_init = InterlockedExchange (&dtoa_CS_init,3);
if (2 == last_CS_init)
{
int i;
for (i = 0; i < NLOCKS; i++)
DeleteCriticalSection (&dtoa_CritSec[i]);
}
long last_CS_init = InterlockedExchange (&dtoa_CS_init,3);
if (2 == last_CS_init) {
int i;
for (i = 0; i < NLOCKS; i++)
DeleteCriticalSection (&dtoa_CritSec[i]);
}
}
static void dtoa_lock(int n)
static void dtoa_lock (int n)
{
if (2 == dtoa_CS_init)
{
EnterCriticalSection (&dtoa_CritSec[n]);
return;
}
if (2 == dtoa_CS_init) {
EnterCriticalSection (&dtoa_CritSec[n]);
return;
}
else if (0 == dtoa_CS_init) {
long last_CS_init = InterlockedExchange (&dtoa_CS_init, 1);
if (0 == last_CS_init) {
int i;
for (i = 0; i < NLOCKS; i++)
InitializeCriticalSection (&dtoa_CritSec[i]);
atexit (dtoa_lock_cleanup);
dtoa_CS_init = 2;
}
else if (2 == last_CS_init)
dtoa_CS_init = 2;
}
/* Another thread is initializing. Wait. */
while (1 == dtoa_CS_init)
Sleep (1);
else if (0 == dtoa_CS_init)
{
long last_CS_init = InterlockedExchange (&dtoa_CS_init, 1);
if (0 == last_CS_init)
{
int i;
for (i = 0; i < NLOCKS; i++)
InitializeCriticalSection (&dtoa_CritSec[i]);
atexit (dtoa_lock_cleanup);
dtoa_CS_init = 2;
}
else if (2 == last_CS_init)
dtoa_CS_init = 2;
}
/* Another thread is initializing. Wait. */
while (1 == dtoa_CS_init)
Sleep (1);
/* It had better be initialized now. */
if (2 == dtoa_CS_init)
EnterCriticalSection(&dtoa_CritSec[n]);
/* It had better be initialized now. */
if (2 == dtoa_CS_init)
EnterCriticalSection(&dtoa_CritSec[n]);
}
static void dtoa_unlock(int n)
static void dtoa_unlock (int n)
{
if (2 == dtoa_CS_init)
LeaveCriticalSection (&dtoa_CritSec[n]);
if (2 == dtoa_CS_init)
LeaveCriticalSection (&dtoa_CritSec[n]);
}
#define ACQUIRE_DTOA_LOCK(n) dtoa_lock(n)
@ -114,10 +108,10 @@ static void dtoa_unlock(int n)
#include "gdtoaimp.h"
#ifndef MULTIPLE_THREADS
char *dtoa_result;
char *dtoa_result;
#endif
static Bigint *freelist[Kmax+1];
static Bigint *freelist[Kmax+1];
#ifndef Omit_Private_Memory
#ifndef PRIVATE_MEM
#define PRIVATE_MEM 2304
@ -126,13 +120,7 @@ static void dtoa_unlock(int n)
static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
#endif
Bigint *
Balloc
#ifdef KR_headers
(k) int k;
#else
(int k)
#endif
Bigint *Balloc (int k)
{
int x;
Bigint *rv;
@ -143,7 +131,7 @@ Balloc
ACQUIRE_DTOA_LOCK(0);
if ( (rv = freelist[k]) !=0) {
freelist[k] = rv->next;
}
}
else {
x = 1 << k;
#ifdef Omit_Private_Memory
@ -154,45 +142,33 @@ Balloc
if (pmem_next - private_mem + len <= PRIVATE_mem) {
rv = (Bigint*)pmem_next;
pmem_next += len;
}
}
else
rv = (Bigint*)MALLOC(len*sizeof(double));
#endif
rv->k = k;
rv->maxwds = x;
}
}
FREE_DTOA_LOCK(0);
rv->sign = rv->wds = 0;
return rv;
}
}
void
Bfree
#ifdef KR_headers
(v) Bigint *v;
#else
(Bigint *v)
#endif
void Bfree (Bigint *v)
{
if (v) {
ACQUIRE_DTOA_LOCK(0);
v->next = freelist[v->k];
freelist[v->k] = v;
FREE_DTOA_LOCK(0);
}
}
}
// Shift y so lowest bit is 1 and return the number of bits y was
// shifted.
// With __GNUC__, we use an inline wrapper for __builtin_clz()
#ifndef __GNUC__
int
lo0bits
#ifdef KR_headers
(y) ULong *y;
#else
(ULong *y)
#endif
int lo0bits (ULong *y)
{
register int k;
register ULong x = *y;
@ -203,46 +179,39 @@ lo0bits
if (x & 2) {
*y = x >> 1;
return 1;
}
}
*y = x >> 2;
return 2;
}
}
k = 0;
if (!(x & 0xffff)) {
k = 16;
x >>= 16;
}
}
if (!(x & 0xff)) {
k += 8;
x >>= 8;
}
}
if (!(x & 0xf)) {
k += 4;
x >>= 4;
}
}
if (!(x & 0x3)) {
k += 2;
x >>= 2;
}
}
if (!(x & 1)) {
k++;
x >>= 1;
if (!x)
return 32;
}
}
*y = x;
return k;
}
}
#endif /* __GNUC__ */
#endif /* __GNUC__ */
Bigint *
multadd
#ifdef KR_headers
(b, m, a) Bigint *b; int m, a;
#else
(Bigint *b, int m, int a) /* multiply by m and add a */
#endif
Bigint *multadd (Bigint *b, int m, int a) /* multiply by m and add a */
{
int i, wds;
#ifdef ULLong
@ -278,66 +247,52 @@ multadd
*x++ = y & 0xffff;
#endif
#endif
}
while(++i < wds);
} while(++i < wds);
if (carry) {
if (wds >= b->maxwds) {
b1 = Balloc(b->k+1);
Bcopy(b1, b);
Bfree(b);
b = b1;
}
}
b->x[wds++] = carry;
b->wds = wds;
}
return b;
}
return b;
}
// With __GNUC__, we use an inline wrapper for __builtin_clz()
#ifndef __GNUC__
int
hi0bits_D2A
#ifdef KR_headers
(x) register ULong x;
#else
(register ULong x)
#endif
int hi0bits_D2A (register ULong x)
{
register int k = 0;
if (!(x & 0xffff0000)) {
k = 16;
x <<= 16;
}
}
if (!(x & 0xff000000)) {
k += 8;
x <<= 8;
}
}
if (!(x & 0xf0000000)) {
k += 4;
x <<= 4;
}
}
if (!(x & 0xc0000000)) {
k += 2;
x <<= 2;
}
}
if (!(x & 0x80000000)) {
k++;
if (!(x & 0x40000000))
return 32;
}
return k;
}
return k;
}
#endif /* __GNUC__ */
#endif
Bigint *
i2b
#ifdef KR_headers
(i) int i;
#else
(int i)
#endif
Bigint *i2b (int i)
{
Bigint *b;
@ -345,15 +300,9 @@ i2b
b->x[0] = i;
b->wds = 1;
return b;
}
}
Bigint *
mult
#ifdef KR_headers
(a, b) Bigint *a, *b;
#else
(Bigint *a, Bigint *b)
#endif
Bigint *mult (Bigint *a, Bigint *b)
{
Bigint *c;
int k, wa, wb, wc;
@ -372,7 +321,7 @@ mult
c = a;
a = b;
b = c;
}
}
k = a->k;
wa = a->wds;
wb = b->wds;
@ -397,11 +346,10 @@ mult
z = *x++ * (ULLong)y + *xc + carry;
carry = z >> 32;
*xc++ = z & 0xffffffffUL;
}
while(x < xae);
} while(x < xae);
*xc = carry;
}
}
}
#else
#ifdef Pack_32
for(; xb < xbe; xb++, xc0++) {
@ -415,8 +363,7 @@ mult
z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
carry = z2 >> 16;
Storeinc(xc, z2, z);
}
while(x < xae);
} while(x < xae);
*xc = carry;
}
if ( (y = *xb >> 16) !=0) {
@ -430,11 +377,10 @@ mult
Storeinc(xc, z, z2);
z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
carry = z2 >> 16;
}
while(x < xae);
} while(x < xae);
*xc = z2;
}
}
}
#else
for(; xb < xbe; xc0++) {
if ( (y = *xb++) !=0) {
@ -445,27 +391,20 @@ mult
z = *x++ * y + *xc + carry;
carry = z >> 16;
*xc++ = z & 0xffff;
}
while(x < xae);
} while(x < xae);
*xc = carry;
}
}
}
#endif
#endif
for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
c->wds = wc;
return c;
}
}
static Bigint *p5s;
static Bigint *p5s;
Bigint *
pow5mult
#ifdef KR_headers
(b, k) Bigint *b; int k;
#else
(Bigint *b, int k)
#endif
Bigint *pow5mult (Bigint *b, int k)
{
Bigint *b1, *p5, *p51;
int i;
@ -483,19 +422,19 @@ pow5mult
if (!(p5 = p5s)) {
p5 = p5s = i2b(625);
p5->next = 0;
}
}
FREE_DTOA_LOCK(1);
#else
p5 = p5s = i2b(625);
p5->next = 0;
#endif
}
}
for(;;) {
if (k & 1) {
b1 = mult(b, p5);
Bfree(b);
b = b1;
}
}
if (!(k >>= 1))
break;
if ((p51 = p5->next) == 0) {
@ -504,26 +443,19 @@ pow5mult
if (!(p51 = p5->next)) {
p51 = p5->next = mult(p5,p5);
p51->next = 0;
}
}
FREE_DTOA_LOCK(1);
#else
p51 = p5->next = mult(p5,p5);
p51->next = 0;
#endif
}
p5 = p51;
}
return b;
p5 = p51;
}
return b;
}
Bigint *
lshift
#ifdef KR_headers
(b, k) Bigint *b; int k;
#else
(Bigint *b, int k)
#endif
Bigint *lshift (Bigint *b, int k)
{
int i, k1, n, n1;
Bigint *b1;
@ -547,8 +479,7 @@ lshift
do {
*x1++ = *x << k | z;
z = *x++ >> k1;
}
while(x < xe);
} while(x < xe);
if ((*x1 = z) !=0)
++n1;
#else
@ -557,27 +488,20 @@ lshift
do {
*x1++ = *x << k & 0xffff | z;
z = *x++ >> k1;
}
while(x < xe);
} while(x < xe);
if (*x1 = z)
++n1;
#endif
}
}
else do
*x1++ = *x++;
while(x < xe);
b1->wds = n1 - 1;
Bfree(b);
return b1;
}
}
int
cmp
#ifdef KR_headers
(a, b) Bigint *a, *b;
#else
(Bigint *a, Bigint *b)
#endif
int cmp (Bigint *a, Bigint *b)
{
ULong *xa, *xa0, *xb, *xb0;
int i, j;
@ -601,17 +525,11 @@ cmp
return *xa < *xb ? -1 : 1;
if (xa <= xa0)
break;
}
return 0;
}
return 0;
}
Bigint *
diff
#ifdef KR_headers
(a, b) Bigint *a, *b;
#else
(Bigint *a, Bigint *b)
#endif
Bigint *diff (Bigint *a, Bigint *b)
{
Bigint *c;
int i, wa, wb;
@ -631,13 +549,13 @@ diff
c->wds = 1;
c->x[0] = 0;
return c;
}
}
if (i < 0) {
c = a;
a = b;
b = c;
i = 1;
}
}
else
i = 0;
c = Balloc(a->k);
@ -655,13 +573,12 @@ diff
y = (ULLong)*xa++ - *xb++ - borrow;
borrow = y >> 32 & 1UL;
*xc++ = y & 0xffffffffUL;
}
while(xb < xbe);
} while(xb < xbe);
while(xa < xae) {
y = *xa++ - borrow;
borrow = y >> 32 & 1UL;
*xc++ = y & 0xffffffffUL;
}
}
#else
#ifdef Pack_32
do {
@ -670,42 +587,34 @@ diff
z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
borrow = (z & 0x10000) >> 16;
Storeinc(xc, z, y);
}
while(xb < xbe);
} while(xb < xbe);
while(xa < xae) {
y = (*xa & 0xffff) - borrow;
borrow = (y & 0x10000) >> 16;
z = (*xa++ >> 16) - borrow;
borrow = (z & 0x10000) >> 16;
Storeinc(xc, z, y);
}
}
#else
do {
y = *xa++ - *xb++ - borrow;
borrow = (y & 0x10000) >> 16;
*xc++ = y & 0xffff;
}
while(xb < xbe);
} while(xb < xbe);
while(xa < xae) {
y = *xa++ - borrow;
borrow = (y & 0x10000) >> 16;
*xc++ = y & 0xffff;
}
}
#endif
#endif
while(!*--xc)
wa--;
c->wds = wa;
return c;
}
}
double
b2d
#ifdef KR_headers
(a, e) Bigint *a; int *e;
#else
(Bigint *a, int *e)
#endif
double b2d (Bigint *a, int *e)
{
ULong *xa, *xa0, w, y, z;
int k;
@ -735,17 +644,17 @@ b2d
w = xa > xa0 ? *--xa : 0;
d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
goto ret_d;
}
}
z = xa > xa0 ? *--xa : 0;
if (k -= Ebits) {
d0 = Exp_1 | y << k | z >> (32 - k);
y = xa > xa0 ? *--xa : 0;
d1 = z << k | y >> (32 - k);
}
}
else {
d0 = Exp_1 | y;
d1 = z;
}
}
#else
if (k < Ebits + 16) {
z = xa > xa0 ? *--xa : 0;
@ -754,7 +663,7 @@ b2d
y = xa > xa0 ? *--xa : 0;
d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
goto ret_d;
}
}
z = xa > xa0 ? *--xa : 0;
w = xa > xa0 ? *--xa : 0;
k -= Ebits + 16;
@ -768,17 +677,11 @@ b2d
word1(d) = d1 >> 16 | d1 << 16;
#endif
return dval(d);
}
#undef d0
#undef d1
}
Bigint *
d2b
#ifdef KR_headers
(val, e, bits) double val; int *e, *bits;
#else
(double val, int *e, int *bits)
#endif
Bigint *d2b (double val, int *e, int *bits)
{
Bigint *b;
#ifndef Sudden_Underflow
@ -826,14 +729,14 @@ d2b
if ( (k = lo0bits(&y)) !=0) {
x[0] = y | z << (32 - k);
z >>= k;
}
}
else
x[0] = y;
#ifndef Sudden_Underflow
i =
#endif
b->wds = (x[1] = z) !=0 ? 2 : 1;
}
}
else {
#ifdef DEBUG
if (!z)
@ -846,7 +749,7 @@ d2b
#endif
b->wds = 1;
k += 32;
}
}
#else
if ( (y = d1) !=0) {
if ( (k = lo0bits(&y)) !=0)
@ -855,22 +758,22 @@ d2b
x[1] = z >> k - 16 & 0xffff;
x[2] = z >> k;
i = 2;
}
}
else {
x[0] = y & 0xffff;
x[1] = y >> 16 | z << 16 - k & 0xffff;
x[2] = z >> k & 0xffff;
x[3] = z >> k+16;
i = 3;
}
}
else {
x[0] = y & 0xffff;
x[1] = y >> 16;
x[2] = z & 0xffff;
x[3] = z >> 16;
i = 3;
}
}
}
else {
#ifdef DEBUG
if (!z)
@ -887,7 +790,7 @@ d2b
i = 1;
}
k += 32;
}
}
while(!x[i])
--i;
b->wds = i + 1;
@ -903,7 +806,7 @@ d2b
*bits = P - k;
#endif
#ifndef Sudden_Underflow
}
}
else {
*e = de - Bias - (P-1) + 1 + k;
#ifdef Pack_32
@ -911,32 +814,31 @@ d2b
#else
*bits = (i+2)*16 - hi0bits(x[i]);
#endif
}
}
#endif
return b;
}
#ifndef __HAVE_GCC44
#undef d
#endif
#undef d0
#undef d1
}
CONST double
const double
#ifdef IEEE_Arith
bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256
};
const double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 };
#else
#ifdef IBM
bigtens[] = { 1e16, 1e32, 1e64 };
CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 };
const double tinytens[] = { 1e-16, 1e-32, 1e-64 };
#else
bigtens[] = { 1e16, 1e32 };
CONST double tinytens[] = { 1e-16, 1e-32 };
const double tinytens[] = { 1e-16, 1e-32 };
#endif
#endif
CONST double
const double
tens[] = {
1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
@ -944,34 +846,23 @@ tens[] = {
#ifdef VAX
, 1e23, 1e24
#endif
};
};
char *
#ifdef KR_headers
strcp_D2A(a, b) char *a; char *b;
#else
strcp_D2A(char *a, CONST char *b)
#endif
char *strcp_D2A (char *a, const char *b)
{
while((*a = *b++))
a++;
return a;
}
}
#ifdef NO_STRING_H
Char *
#ifdef KR_headers
memcpy_D2A(a, b, len) Char *a; Char *b; size_t len;
#else
memcpy_D2A(void *a1, void *b1, size_t len)
#endif
void *memcpy_D2A (void *a1, void *b1, size_t len)
{
register char *a = (char*)a1, *ae = a + len;
register char *b = (char*)b1, *a0 = a;
while(a < ae)
*a++ = *b++;
return a0;
}
}
#endif /* NO_STRING_H */

View File

@ -31,13 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
Bigint *
s2b
#ifdef KR_headers
(s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;
#else
(CONST char *s, int nd0, int nd, ULong y9)
#endif
Bigint *s2b (const char *s, int nd0, int nd, ULong y9)
{
Bigint *b;
int i, k;
@ -61,21 +55,15 @@ s2b
do b = multadd(b, 10, *s++ - '0');
while(++i < nd0);
s++;
}
}
else
s += 10;
for(; i < nd; i++)
b = multadd(b, 10, *s++ - '0');
return b;
}
}
double
ratio
#ifdef KR_headers
(a, b) Bigint *a, *b;
#else
(Bigint *a, Bigint *b)
#endif
double ratio (Bigint *a, Bigint *b)
{
#ifdef __HAVE_GCC44
union _dbl_union da, db;
@ -92,54 +80,43 @@ ratio
word0(da) += (k >> 2)*Exp_msk1;
if (k &= 3)
dval(da) *= 1 << k;
}
}
else {
k = -k;
word0(db) += (k >> 2)*Exp_msk1;
if (k &= 3)
dval(db) *= 1 << k;
}
}
#else
if (k > 0)
word0(da) += k*Exp_msk1;
else {
k = -k;
word0(db) += k*Exp_msk1;
}
}
#endif
return dval(da) / dval(db);
}
}
#ifdef INFNAN_CHECK
int
match
#ifdef KR_headers
(sp, t) char **sp, *t;
#else
(CONST char **sp, char *t)
#endif
int match (const char **sp, char *t)
{
int c, d;
CONST char *s = *sp;
const char *s = *sp;
while( (d = *t++) !=0) {
if ((c = *++s) >= 'A' && c <= 'Z')
c += 'a' - 'A';
if (c != d)
return 0;
}
}
*sp = s + 1;
return 1;
}
}
#endif /* INFNAN_CHECK */
void
#ifdef KR_headers
copybits(c, n, b) ULong *c; int n; Bigint *b;
#else
copybits(ULong *c, int n, Bigint *b)
#endif
void copybits (ULong *c, int n, Bigint *b)
{
ULong *ce, *x, *xe;
#ifdef Pack_16
@ -162,14 +139,9 @@ copybits(ULong *c, int n, Bigint *b)
#endif
while(c < ce)
*c++ = 0;
}
}
ULong
#ifdef KR_headers
any_on(b, k) Bigint *b; int k;
#else
any_on(Bigint *b, int k)
#endif
ULong any_on (Bigint *b, int k)
{
int n, nwds;
ULong *x, *x0, x1, x2;
@ -185,11 +157,11 @@ any_on(Bigint *b, int k)
x1 <<= k;
if (x1 != x2)
return 1;
}
}
x0 = x;
x += n;
while(x > x0)
if (*--x)
return 1;
return 0;
}
}

View File

@ -35,21 +35,16 @@ THIS SOFTWARE.
#include "locale.h"
#endif
static CONST int
static const int
fivesbits[] = { 0, 3, 5, 7, 10, 12, 14, 17, 19, 21,
24, 26, 28, 31, 33, 35, 38, 40, 42, 45,
47, 49, 52
#ifdef VAX
, 54, 56
#endif
};
};
Bigint *
#ifdef KR_headers
increment(b) Bigint *b;
#else
increment(Bigint *b)
#endif
Bigint *increment (Bigint *b)
{
ULong *x, *xe;
Bigint *b1;
@ -64,9 +59,9 @@ increment(Bigint *b)
if (*x < (ULong)0xffffffffL) {
++*x;
return b;
}
}
*x++ = 0;
} while(x < xe);
} while(x < xe);
#else
do {
y = *x + carry;
@ -74,7 +69,7 @@ increment(Bigint *b)
*x++ = y & 0xffff;
if (!carry)
return b;
} while(x < xe);
} while(x < xe);
if (carry)
#endif
{
@ -83,18 +78,13 @@ increment(Bigint *b)
Bcopy(b1,b);
Bfree(b);
b = b1;
}
b->x[b->wds++] = 1;
}
return b;
b->x[b->wds++] = 1;
}
return b;
}
int
#ifdef KR_headers
decrement(b) Bigint *b;
#else
decrement(Bigint *b)
#endif
int decrement (Bigint *b)
{
ULong *x, *xe;
#ifdef Pack_16
@ -108,26 +98,20 @@ decrement(Bigint *b)
if (*x) {
--*x;
break;
}
*x++ = 0xffffffffL;
}
while(x < xe);
*x++ = 0xffffffffL;
} while(x < xe);
#else
do {
y = *x - borrow;
borrow = (y & 0x10000) >> 16;
*x++ = y & 0xffff;
} while(borrow && x < xe);
} while(borrow && x < xe);
#endif
return STRTOG_Inexlo;
}
}
static int
#ifdef KR_headers
all_on(b, n) Bigint *b; int n;
#else
all_on(Bigint *b, int n)
#endif
static int all_on (Bigint *b, int n)
{
ULong *x, *xe;
@ -139,14 +123,9 @@ all_on(Bigint *b, int n)
if (n &= kmask)
return ((*x | (ALL_ON << n)) & ALL_ON) == ALL_ON;
return 1;
}
}
Bigint *
#ifdef KR_headers
set_ones(b, n) Bigint *b; int n;
#else
set_ones(Bigint *b, int n)
#endif
Bigint *set_ones (Bigint *b, int n)
{
int k;
ULong *x, *xe;
@ -155,7 +134,7 @@ set_ones(Bigint *b, int n)
if (b->k < k) {
Bfree(b);
b = Balloc(k);
}
}
k = n >> kshift;
if (n &= kmask)
k++;
@ -167,16 +146,10 @@ set_ones(Bigint *b, int n)
if (n)
x[-1] >>= ULbits - n;
return b;
}
}
static int
rvOK
#ifdef KR_headers
(d, fpi, exp, bits, exact, rd, irv)
double d; FPI *fpi; Long *exp; ULong *bits; int exact, rd, *irv;
#else
(double d, FPI *fpi, Long *exp, ULong *bits, int exact, int rd, int *irv)
#endif
static int rvOK (double d, FPI *fpi, Long *exp, ULong *bits,
int exact, int rd, int *irv)
{
Bigint *b;
ULong carry, inex, lostbits;
@ -190,7 +163,7 @@ rvOK
if (exact)
goto trunc;
goto ret;
}
}
if (P == nb) {
if (
#ifndef IMPRECISE_INEXACT
@ -204,7 +177,7 @@ rvOK
#endif
) goto trunc;
goto ret;
}
}
switch(rd) {
case 1:
goto trunc;
@ -220,11 +193,11 @@ rvOK
if (b->x[0] & 2)
break;
goto trunc;
}
}
if (b->x[k>>kshift] & ((ULong)1 << (k & kmask)))
break;
goto trunc;
}
}
/* "break" cases: round up 1 bit, then truncate; bdif > 0 */
carry = 1;
trunc:
@ -243,9 +216,9 @@ rvOK
lostbits = b->x[0] & 1;
rshift(b, 1);
e++;
}
}
}
}
else if (bdif < 0)
b = lshift(b, -bdif);
if (e < fpi->emin) {
@ -254,7 +227,7 @@ rvOK
if (k > nb || fpi->sudden_underflow) {
b->wds = inex = 0;
*irv = STRTOG_Underflow | STRTOG_Inexlo;
}
}
else {
k1 = k - 1;
if (k1 > 0 && !lostbits)
@ -268,11 +241,11 @@ rvOK
if (carry) {
b = increment(b);
inex = STRTOG_Inexhi | STRTOG_Underflow;
}
}
else if (lostbits)
inex = STRTOG_Inexlo | STRTOG_Underflow;
}
}
}
else if (e > fpi->emax) {
e = fpi->emax + 1;
*irv = STRTOG_Infinite | STRTOG_Overflow | STRTOG_Inexhi;
@ -280,7 +253,7 @@ rvOK
errno = ERANGE;
#endif
b->wds = inex = 0;
}
}
*exp = e;
copybits(bits, nb, b);
*irv |= inex;
@ -288,14 +261,9 @@ rvOK
ret:
Bfree(b);
return rv;
}
}
static int
#ifdef KR_headers
mantbits(val) double val;
#else
mantbits(double val)
#endif
static int mantbits (double val)
{
ULong L;
#ifdef __HAVE_GCC44
@ -317,26 +285,19 @@ mantbits(double val)
L = word0(d) | Exp_msk1;
#endif
return P - 32 - lo0bits(&L);
}
#ifndef __HAVE_GCC44
#undef d
#endif
}
int
__strtodg
#ifdef KR_headers
(s00, se, fpi, exp, bits)
CONST char *s00; char **se; FPI *fpi; Long *exp; ULong *bits;
#else
(CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
#endif
int __strtodg (const char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
{
int abe, abits, asub;
int bb0, bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, decpt, denorm;
int dsign, e, e1, e2, emin, esign, finished, i, inex, irv;
int j, k, nbits, nd, nd0, nf, nz, nz0, rd, rvbits, rve, rve1, sign;
int sudden_underflow;
CONST char *s, *s0, *s1;
const char *s, *s0, *s1;
double adj0, tol;
#ifdef __HAVE_GCC44
union _dbl_union adj, rv;
@ -374,7 +335,7 @@ __strtodg
continue;
default:
goto break2;
}
}
break2:
if (*s == '0') {
#ifndef NO_HEX_FP
@ -387,13 +348,13 @@ __strtodg
sign = 0;
}
goto ret;
}
}
#endif
nz0 = 1;
while(*++s == '0') ;
if (!*s)
goto ret;
}
}
sudden_underflow = fpi->sudden_underflow;
s0 = s;
y = z = 0;
@ -408,7 +369,7 @@ __strtodg
#else
if (c == '.')
#endif
{
{
decpt = 1;
c = *++s;
if (!nd) {
@ -419,9 +380,9 @@ __strtodg
nf += nz;
nz = 0;
goto have_dig;
}
goto dig_done;
}
goto dig_done;
}
for(; c >= '0' && c <= '9'; c = *++s) {
have_dig:
nz++;
@ -437,9 +398,9 @@ __strtodg
else if (nd <= DBL_DIG + 1)
z = 10*z + c;
nz = 0;
}
}
}
}
dig_done:
e = 0;
if (c == 'e' || c == 'E') {
@ -447,7 +408,7 @@ __strtodg
irv = STRTOG_NoNumber;
s = s00;
goto ret;
}
}
s00 = s;
esign = 0;
switch(c = *++s) {
@ -455,7 +416,7 @@ __strtodg
esign = 1;
case '+':
c = *++s;
}
}
if (c >= '0' && c <= '9') {
while(c == '0')
c = *++s;
@ -473,13 +434,13 @@ __strtodg
e = (int)L;
if (esign)
e = -e;
}
}
else
e = 0;
}
}
else
s = s00;
}
}
if (!nd) {
if (!nz && !nz0) {
#ifdef INFNAN_CHECK
@ -494,7 +455,7 @@ __strtodg
++s;
irv = STRTOG_Infinite;
goto infnanexp;
}
}
break;
case 'n':
case 'N':
@ -506,14 +467,14 @@ __strtodg
irv = hexnan(&s, fpi, bits);
#endif
goto infnanexp;
}
}
}
}
#endif /* INFNAN_CHECK */
irv = STRTOG_NoNumber;
s = s00;
}
goto ret;
}
goto ret;
}
irv = STRTOG_Normal;
e1 = e -= nf;
@ -527,7 +488,7 @@ __strtodg
break;
case FPI_Round_down:
rd = 1 + sign;
}
}
/* Now we have nd0 digits, starting at s0, followed by a
* decimal point, followed by nd-nd0 digits. The number we're
@ -545,7 +506,7 @@ __strtodg
if (!e) {
if (rvOK(dval(rv), fpi, exp, bits, 1, rd, &irv))
goto ret;
}
}
else if (e > 0) {
if (e <= Ten_pmax) {
#ifdef VAX
@ -558,7 +519,7 @@ __strtodg
e1 -= e;
goto rv_notOK;
#endif
}
}
i = DBL_DIG - nd;
if (e <= Ten_pmax + i) {
/* A fancier test would sometimes let us do
@ -586,17 +547,17 @@ __strtodg
if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv))
goto ret;
e1 -= e2;
}
}
}
#ifndef Inaccurate_Divide
else if (e >= -Ten_pmax) {
/* rv = */ rounded_quotient(dval(rv), tens[-e]);
if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv))
goto ret;
e1 -= e;
}
#endif
}
#endif
}
rv_notOK:
e1 += nd - k;
@ -615,15 +576,15 @@ __strtodg
word0(rv) |= Bias << Exp_shift1;
dval(rv) *= bigtens[n_bigtens-1];
e1 -= 1 << (n_bigtens-1);
}
}
e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;
word0(rv) &= ~Exp_mask;
word0(rv) |= Bias << Exp_shift1;
for(j = 0; e1 > 0; j++, e1 >>= 1)
if (e1 & 1)
dval(rv) *= bigtens[j];
}
}
}
else if (e1 < 0) {
e1 = -e1;
if ( (i = e1 & 15) !=0)
@ -637,15 +598,15 @@ __strtodg
word0(rv) |= Bias << Exp_shift1;
dval(rv) *= tinytens[n_bigtens-1];
e1 -= 1 << (n_bigtens-1);
}
}
e2 += ((word0(rv) & Exp_mask) >> Exp_shift1) - Bias;
word0(rv) &= ~Exp_mask;
word0(rv) |= Bias << Exp_shift1;
for(j = 0; e1 > 0; j++, e1 >>= 1)
if (e1 & 1)
dval(rv) *= tinytens[j];
}
}
}
#ifdef IBM
/* e2 is a correction to the (base 2) exponent of the return
* value, reflecting adjustments above to avoid overflow in the
@ -660,7 +621,7 @@ __strtodg
rshift(rvb, j);
rvbits = nbits;
rve += j;
}
}
bb0 = 0; /* trailing zero bits in rvb */
e2 = rve + rvbits - nbits;
if (e2 > fpi->emax + 1)
@ -672,7 +633,7 @@ __strtodg
if (j > 0) {
rvb = lshift(rvb, j);
rvbits += j;
}
}
else if (j < 0) {
rvbits += j;
if (rvbits <= 0) {
@ -683,16 +644,16 @@ __strtodg
*exp = emin;
irv = STRTOG_Underflow | STRTOG_Inexlo;
goto ret;
}
rvb->x[0] = rvb->wds = rvbits = 1;
}
rvb->x[0] = rvb->wds = rvbits = 1;
}
else
rshift(rvb, -j);
}
}
rve = rve1 = emin;
if (sudden_underflow && e2 + 1 < emin)
goto ufl;
}
}
/* Now the hard part -- adjusting rv to the correct value.*/
@ -712,11 +673,11 @@ __strtodg
if (e >= 0) {
bb2 = bb5 = 0;
bd2 = bd5 = e;
}
}
else {
bb2 = bb5 = -e;
bd2 = bd5 = 0;
}
}
if (bbe >= 0)
bb2 += bbe;
else
@ -735,13 +696,13 @@ __strtodg
bb2 -= i;
bd2 -= i;
bs2 -= i;
}
}
if (bb5 > 0) {
bs = pow5mult(bs, bb5);
bb1 = mult(bs, bb);
Bfree(bb);
bb = bb1;
}
}
bb2 -= bb0;
if (bb2 > 0)
bb = lshift(bb, bb2);
@ -768,7 +729,7 @@ __strtodg
if (dsign != 0) {
irv |= STRTOG_Inexhi;
goto adj1;
}
}
irv |= STRTOG_Inexlo;
if (rve1 == emin)
goto adj1;
@ -776,16 +737,16 @@ __strtodg
i++, j -= ULbits) {
if (rvb->x[i] & ALL_ON)
goto adj1;
}
}
if (j > 1 && lo0bits(rvb->x + i) < j - 1)
goto adj1;
rve = rve1 - 1;
rvb = set_ones(rvb, rvbits = nbits);
break;
}
}
irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi;
break;
}
}
if (i < 0) {
/* Error is less than half an ulp -- check for
* special case of mantissa a power of two.
@ -799,9 +760,9 @@ __strtodg
if (cmp(delta, bs) > 0) {
irv = STRTOG_Normal | STRTOG_Inexlo;
goto drop_down;
}
break;
}
break;
}
if (i == 0) {
/* exactly half-way between */
if (dsign) {
@ -813,9 +774,9 @@ __strtodg
irv = STRTOG_Normal | STRTOG_Inexhi;
denorm = 0;
break;
}
irv = STRTOG_Normal | STRTOG_Inexlo;
}
irv = STRTOG_Normal | STRTOG_Inexlo;
}
else if (bbbits == 1) {
irv = STRTOG_Normal;
drop_down:
@ -825,11 +786,11 @@ __strtodg
if (rvb->wds == 1 && rvb->x[0] == 1)
sudden_underflow = 1;
break;
}
}
rve -= nbits;
rvb = set_ones(rvb, rvbits = nbits);
break;
}
}
else
irv = STRTOG_Normal | STRTOG_Inexhi;
if ((bbbits < nbits && !denorm) || !(rvb->x[0] & 1))
@ -842,37 +803,37 @@ __strtodg
!= j)
rvbits++;
irv = STRTOG_Normal | STRTOG_Inexhi;
}
}
else {
if (bbbits == 1)
goto undfl;
decrement(rvb);
irv = STRTOG_Normal | STRTOG_Inexlo;
}
break;
}
break;
}
if ((dval(adj) = ratio(delta, bs)) <= 2.) {
adj1:
inex = STRTOG_Inexlo;
if (dsign) {
asub = 0;
inex = STRTOG_Inexhi;
}
}
else if (denorm && bbbits <= 1) {
undfl:
rvb->wds = 0;
rve = emin;
irv = STRTOG_Underflow | STRTOG_Inexlo;
break;
}
adj0 = dval(adj) = 1.;
}
adj0 = dval(adj) = 1.;
}
else {
adj0 = dval(adj) *= 0.5;
if (dsign) {
asub = 0;
inex = STRTOG_Inexlo;
}
}
if (dval(adj) < 2147483647.) {
L = adj0;
adj0 -= L;
@ -890,11 +851,11 @@ __strtodg
inc_L:
L++;
inex = STRTOG_Inexact - inex;
}
}
dval(adj) = L;
}
}
dval(adj) = L;
}
}
y = rve + rvbits;
/* adj *= ulp(dval(rv)); */
@ -904,7 +865,7 @@ __strtodg
rvb = lshift(rvb, j = nbits - rvbits);
rve -= j;
rvbits = nbits;
}
}
ab = d2b(dval(adj), &abe, &abits);
if (abe < 0)
rshift(ab, -abe);
@ -925,15 +886,15 @@ __strtodg
if (rve1 == emin) {
--rvbits;
denorm = 1;
}
}
else {
rvb = lshift(rvb, 1);
--rve;
--rve1;
L = finished = 0;
}
}
}
}
else {
rvb = sum(rvb, ab);
k = rvb->wds - 1;
@ -942,15 +903,15 @@ __strtodg
if (denorm) {
if (++rvbits == nbits)
denorm = 0;
}
}
else {
rshift(rvb, 1);
rve++;
rve1++;
L = 0;
}
}
}
}
Bfree(ab);
Bfree(rvb0);
if (finished)
@ -965,26 +926,26 @@ __strtodg
if (adj0 > tol) {
irv |= inex;
break;
}
}
}
else if (dval(adj) > tol && adj0 < 1. - tol) {
irv |= inex;
break;
}
}
}
bb0 = denorm ? 0 : trailz(rvb);
Bfree(bb);
Bfree(bd);
Bfree(bs);
Bfree(delta);
}
}
if (!denorm && (j = nbits - rvbits)) {
if (j > 0)
rvb = lshift(rvb, j);
else
rshift(rvb, -j);
rve -= j;
}
}
*exp = rve;
Bfree(bb);
Bfree(bd);
@ -1000,20 +961,20 @@ __strtodg
#endif
infnanexp:
*exp = fpi->emax + 1;
}
}
ret:
if (denorm) {
if (sudden_underflow) {
rvb->wds = 0;
irv = STRTOG_Underflow | STRTOG_Inexlo;
}
}
else {
irv = (irv & ~STRTOG_Retmask) |
(rvb->wds > 0 ? STRTOG_Denormal : STRTOG_Zero);
if (irv & STRTOG_Inexact)
irv |= STRTOG_Underflow;
}
}
}
if (se)
*se = (char *)s;
if (sign)
@ -1021,6 +982,6 @@ __strtodg
if (rvb) {
copybits(bits, nbits, rvb);
Bfree(rvb);
}
return irv;
}
return irv;
}

View File

@ -37,12 +37,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
double
#ifdef KR_headers
__strtod(s, sp) CONST char *s; char **sp;
#else
__strtod(CONST char *s, char **sp)
#endif
double __strtod (const char *s, char **sp)
{
static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
ULong bits[2];
@ -80,8 +75,8 @@ __strtod(CONST char *s, char **sp)
case STRTOG_NaNbits:
u.L[_0] = 0x7ff00000 | bits[1];
u.L[_1] = bits[0];
}
}
if (k & STRTOG_Neg)
u.L[_0] |= 0x80000000L;
return u.d;
}
}

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
float
#ifdef KR_headers
__strtof(s, sp) CONST char *s; char **sp;
#else
__strtof(CONST char *s, char **sp)
#endif
float __strtof (const char *s, char **sp)
{
static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
ULong bits[1];
@ -66,11 +61,11 @@ __strtof(CONST char *s, char **sp)
case STRTOG_NaN:
u.L[0] = f_QNAN;
}
}
if (k & STRTOG_Neg)
u.L[0] |= 0x80000000L;
return u.f;
}
}
float __cdecl
strtof (const char * __restrict__ src, char ** __restrict__ endptr)

View File

@ -52,23 +52,18 @@ THIS SOFTWARE.
#endif
typedef union lD {
UShort L[5];
long double D;
UShort L[5];
long double D;
} lD;
static int
#ifdef KR_headers
__strtopx(s, sp, V) CONST char *s; char **sp; lD *V;
#else
__strtopx(CONST char *s, char **sp, lD *V)
#endif
static int __strtopx (const char *s, char **sp, lD *V)
{
static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
ULong bits[2];
Long exp;
int k;
UShort *L = & (V->L[0]);
V->D=0.0L;
V->D = 0.0L;
k = __strtodg(s, sp, &fpi, &exp, bits);
switch(k & STRTOG_Retmask) {
@ -103,24 +98,21 @@ __strtopx(CONST char *s, char **sp, lD *V)
L[2] = ldus_QNAN2;
L[3] = ldus_QNAN3;
L[4] = ldus_QNAN4;
}
}
if (k & STRTOG_Neg)
L[_0] |= 0x8000;
return k;
}
long double
__cdecl
__strtold (const char * __restrict__ src, char ** __restrict__ endptr)
{
lD ret;
ret.D = 0.0L;
__strtopx(src, endptr, &ret);
return ret.D;
}
long double
__cdecl
long double __cdecl
__strtold (const char * __restrict__ src, char ** __restrict__ endptr)
{
long double ret = 0.0;
__strtopx(src, endptr, &ret);
return ret;
}
long double __cdecl
strtold (const char * __restrict__ src, char ** __restrict__ endptr)
__attribute__((alias("__strtold")));

View File

@ -31,12 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
Bigint *
#ifdef KR_headers
sum(a, b) Bigint *a; Bigint *b;
#else
sum(Bigint *a, Bigint *b)
#endif
Bigint *sum (Bigint *a, Bigint *b)
{
Bigint *c;
ULong carry, *xc, *xa, *xb, *xe, y;
@ -46,7 +41,7 @@ sum(Bigint *a, Bigint *b)
if (a->wds < b->wds) {
c = b; b = a; a = c;
}
}
c = Balloc(a->k);
c->wds = a->wds;
carry = 0;
@ -61,8 +56,7 @@ sum(Bigint *a, Bigint *b)
z = (*xa++ >> 16) + (*xb++ >> 16) + carry;
carry = (z & 0x10000) >> 16;
Storeinc(xc, z, y);
}
while(xc < xe);
} while(xc < xe);
xe += a->wds - b->wds;
while(xc < xe) {
y = (*xa & 0xffff) + carry;
@ -70,20 +64,19 @@ sum(Bigint *a, Bigint *b)
z = (*xa++ >> 16) + carry;
carry = (z & 0x10000) >> 16;
Storeinc(xc, z, y);
}
}
#else
do {
y = *xa++ + *xb++ + carry;
carry = (y & 0x10000) >> 16;
*xc++ = y & 0xffff;
}
while(xc < xe);
} while(xc < xe);
xe += a->wds - b->wds;
while(xc < xe) {
y = *xa++ + carry;
carry = (y & 0x10000) >> 16;
*xc++ = y & 0xffff;
}
}
#endif
if (carry) {
if (c->wds == c->maxwds) {
@ -91,8 +84,8 @@ sum(Bigint *a, Bigint *b)
Bcopy(b, c);
Bfree(c);
c = b;
}
c->x[c->wds++] = 1;
}
return c;
c->x[c->wds++] = 1;
}
return c;
}

View File

@ -31,13 +31,7 @@ THIS SOFTWARE.
#include "gdtoaimp.h"
double
ulp
#ifdef KR_headers
(x) double x;
#else
(double x)
#endif
double ulp (double x)
{
Long L;
#ifdef __HAVE_GCC44
@ -58,23 +52,23 @@ ulp
word0(a) = L;
word1(a) = 0;
#ifndef Sudden_Underflow
}
}
else {
L = -L >> Exp_shift;
if (L < Exp_shift) {
word0(a) = 0x80000 >> L;
word1(a) = 0;
}
}
else {
word0(a) = 0;
L -= Exp_shift;
word1(a) = L >= 31 ? 1 : 1 << (31 - L);
}
}
}
#endif
#ifdef __HAVE_GCC44
return dval(a);
#else
return a;
#endif
}
}