198#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
208#ifdef Honor_FLT_ROUNDS
209#ifndef Trust_FLT_ROUNDS
218extern void *
MALLOC(
size_t);
224#ifndef Omit_Private_Memory
226#define PRIVATE_MEM 2304
228#define PRIVATE_mem ((PRIVATE_MEM+sizeof(double)-1)/sizeof(double))
229static double private_mem[
PRIVATE_mem], *pmem_next = private_mem;
233#undef Avoid_Underflow
242#ifndef NO_INFNAN_CHECK
248#define NO_STRTOD_BIGCOMP
257#define DBL_MAX_10_EXP 308
258#define DBL_MAX_EXP 1024
264#define DBL_MAX_10_EXP 75
265#define DBL_MAX_EXP 63
267#define DBL_MAX 7.2370055773322621e+75
272#define DBL_MAX_10_EXP 38
273#define DBL_MAX_EXP 127
275#define DBL_MAX 1.7014118346046923e+38
279#define LONG_MAX 2147483647
302#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
309#define word0(x) (x)->L[1]
310#define word1(x) (x)->L[0]
312#define word0(x) (x)->L[0]
313#define word1(x) (x)->L[1]
315#define dval(x) (x)->d
318#define STRTOD_DIGLIM 40
324#define strtod_diglim STRTOD_DIGLIM
331#if defined(IEEE_8087) + defined(VAX)
332#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
333((unsigned short *)a)[0] = (unsigned short)c, a++)
335#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
336((unsigned short *)a)[1] = (unsigned short)c, a++)
348#define Exp_msk1 0x100000
349#define Exp_msk11 0x100000
350#define Exp_mask 0x7ff00000
356#define Exp_1 0x3ff00000
357#define Exp_11 0x3ff00000
359#define Frac_mask 0xfffff
360#define Frac_mask1 0xfffff
363#define Bndry_mask 0xfffff
364#define Bndry_mask1 0xfffff
366#define Sign_bit 0x80000000
373#define Avoid_Underflow
375#undef Sudden_Underflow
381#define Flt_Rounds FLT_ROUNDS
387#ifdef Honor_FLT_ROUNDS
388#undef Check_FLT_ROUNDS
389#define Check_FLT_ROUNDS
391#define Rounding Flt_Rounds
395#undef Check_FLT_ROUNDS
396#undef Honor_FLT_ROUNDS
398#undef Sudden_Underflow
399#define Sudden_Underflow
405#define Exp_msk1 0x1000000
406#define Exp_msk11 0x1000000
407#define Exp_mask 0x7f000000
413#define Exp_1 0x41000000
414#define Exp_11 0x41000000
416#define Frac_mask 0xffffff
417#define Frac_mask1 0xffffff
420#define Bndry_mask 0xefffff
421#define Bndry_mask1 0xffffff
423#define Sign_bit 0x80000000
425#define Tiny0 0x100000
435#define Exp_msk11 0x800000
436#define Exp_mask 0x7f80
442#define Exp_1 0x40800000
445#define Frac_mask 0x7fffff
446#define Frac_mask1 0xffff007f
449#define Bndry_mask 0xffff007f
450#define Bndry_mask1 0xffff007f
452#define Sign_bit 0x8000
464#ifdef ROUND_BIASED_without_Round_Up
471#define rounded_product(a,b) a = rnd_prod(a, b)
472#define rounded_quotient(a,b) a = rnd_quot(a, b)
474extern double rnd_prod(), rnd_quot();
476extern double rnd_prod(
double,
double), rnd_quot(
double,
double);
479#define rounded_product(a,b) a *= b
480#define rounded_quotient(a,b) a /= b
483#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
484#define Big1 0xffffffff
492BCinfo {
int dp0,
dp1,
dplen,
dsign,
e0,
inexact,
nd,
nd0,
rounding,
scale,
uflchk; };
495#define FFFFFFFF ((((unsigned long)0xffff)<<16)|(unsigned long)0xffff)
497#define FFFFFFFF 0xffffffffUL
512#define Llong long long
515#define ULLong unsigned Llong
519#ifndef MULTIPLE_THREADS
520#define ACQUIRE_DTOA_LOCK(n)
521#define FREE_DTOA_LOCK(n)
527extern "C" double strtod(
const char *s00,
char **se);
528extern "C" char *
dtoa(
double d,
int mode,
int ndigits,
529 int *decpt,
int *sign,
char **rve);
553#ifndef Omit_Private_Memory
560 if (
k <=
Kmax && (
rv = freelist[
k]))
564#ifdef Omit_Private_Memory
580 rv->sign =
rv->wds = 0;
601 v->next = freelist[v->k];
608#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
609y->wds*sizeof(Long) + 2*sizeof(int))
643 y = (xi & 0xffff) * m + carry;
644 z = (xi >> 16) * m + (y >> 16);
646 *
x++ = (z << 16) + (y & 0xffff);
656 if (
wds >= b->maxwds) {
671 (
s, nd0, nd, y9, dplen)
CONST char *
s;
int nd0, nd, dplen;
ULong y9;
673 (
const char *
s,
int nd0,
int nd,
ULong y9,
int dplen)
681 for(
k = 0, y = 1;
x >
y;
y <<= 1,
k++) ;
688 b->
x[0] = y9 & 0xffff;
689 b->
wds = (b->
x[1] = y9 >> 16) ? 2 : 1;
695 do b = multadd(b, 10, *
s++ -
'0');
702 b = multadd(b, 10, *
s++ -
'0');
716 if (!(
x & 0xffff0000)) {
720 if (!(
x & 0xff000000)) {
724 if (!(
x & 0xf0000000)) {
728 if (!(
x & 0xc0000000)) {
732 if (!(
x & 0x80000000)) {
734 if (!(
x & 0x40000000))
814 ULong *
x, *xa, *xae, *xb, *xbe, *xc, *xc0;
825 if (
a->wds < b->
wds) {
837 for(
x = c->
x, xa =
x + wc;
x < xa;
x++)
845 for(; xb < xbe; xc0++) {
851 z = *
x++ * (
ULLong)y + *xc + carry;
861 for(; xb < xbe; xb++, xc0++) {
862 if (y = *xb & 0xffff) {
867 z = (*
x & 0xffff) * y + (*xc & 0xffff) + carry;
869 z2 = (*
x++ >> 16) * y + (*xc >> 16) + carry;
882 z = (*
x & 0xffff) * y + (*xc >> 16) + carry;
885 z2 = (*
x++ >> 16) * y + (*xc & 0xffff) + carry;
893 for(; xb < xbe; xc0++) {
899 z = *
x++ *
y + *xc + carry;
909 for(xc0 = c->
x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
926 static int p05[3] = { 5, 25, 125 };
929 b = multadd(b, p05[i-1], 0);
935#ifdef MULTIPLE_THREADS
955 if (!(p51 = p5->
next)) {
956#ifdef MULTIPLE_THREADS
958 if (!(p51 = p5->
next)) {
959 p51 = p5->
next = mult(p5,p5);
964 p51 = p5->
next = mult(p5,p5);
992 for(i = b->maxwds; n1 > i; i <<= 1)
996 for(i = 0; i < n; i++)
1005 *x1++ = *
x <<
k | z;
1017 *x1++ = *
x <<
k & 0xffff | z;
1041 ULong *xa, *xa0, *xb, *xb0;
1047 if (i > 1 && !
a->x[i-1])
1048 Bug(
"cmp called with a->x[a->wds-1] == 0");
1049 if (
j > 1 && !b->x[
j-1])
1050 Bug(
"cmp called with b->x[b->wds-1] == 0");
1060 return *xa < *xb ? -1 : 1;
1077 ULong *xa, *xae, *xb, *xbe, *xc;
1114 y = (
ULLong)*xa++ - *xb++ - borrow;
1115 borrow =
y >> 32 & (
ULong)1;
1121 borrow =
y >> 32 & (
ULong)1;
1127 y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
1128 borrow = (
y & 0x10000) >> 16;
1129 z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
1130 borrow = (z & 0x10000) >> 16;
1135 y = (*xa & 0xffff) - borrow;
1136 borrow = (
y & 0x10000) >> 16;
1137 z = (*xa++ >> 16) - borrow;
1138 borrow = (z & 0x10000) >> 16;
1143 y = *xa++ - *xb++ - borrow;
1144 borrow = (
y & 0x10000) >> 16;
1150 borrow = (
y & 0x10000) >> 16;
1173#ifndef Avoid_Underflow
1174#ifndef Sudden_Underflow
1183#ifndef Avoid_Underflow
1184#ifndef Sudden_Underflow
1189 word0(&u) = 0x80000 >> L;
1195 word1(&u) = L >= 31 ? 1 : 1 << 31 - L;
1211 ULong *xa, *xa0, w,
y, z;
1225 if (!y) Bug(
"zero y in b2d");
1232 w = xa > xa0 ? *--xa : 0;
1236 z = xa > xa0 ? *--xa : 0;
1238 d0 =
Exp_1 | y << k | z >> (32 -
k);
1239 y = xa > xa0 ? *--xa : 0;
1240 d1 = z << k | y >> (32 -
k);
1248 z = xa > xa0 ? *--xa : 0;
1250 w = xa > xa0 ? *--xa : 0;
1251 y = xa > xa0 ? *--xa : 0;
1255 z = xa > xa0 ? *--xa : 0;
1256 w = xa > xa0 ? *--xa : 0;
1258 d0 =
Exp_1 | y << k + 16 | z << k | w >> 16 -
k;
1259 y = xa > xa0 ? *--xa : 0;
1260 d1 = w <<
k + 16 |
y <<
k;
1276 (
d, e, bits)
U *d;
int *e, *bits;
1278 (
U *
d,
int *e,
int *bits)
1284#ifndef Sudden_Underflow
1305#ifdef Sudden_Underflow
1316 if ((
k = lo0bits(&y))) {
1317 x[0] =
y | z << (32 -
k);
1322#ifndef Sudden_Underflow
1325 b->
wds = (
x[1] = z) ? 2 : 1;
1330#ifndef Sudden_Underflow
1338 if (
k = lo0bits(&y))
1340 x[0] =
y | z << 32 -
k & 0xffff;
1341 x[1] = z >>
k - 16 & 0xffff;
1347 x[1] =
y >> 16 | z << 16 -
k & 0xffff;
1348 x[2] = z >>
k & 0xffff;
1363 Bug(
"Zero passed to d2b");
1381#ifndef Sudden_Underflow
1385 *e = (de -
Bias - (
P-1) << 2) +
k;
1388 *e = de -
Bias - (
P-1) +
k;
1391#ifndef Sudden_Underflow
1394 *e = de -
Bias - (
P-1) + 1 +
k;
1396 *bits = 32*i - hi0bits(
x[i-1]);
1398 *bits = (i+2)*16 - hi0bits(
x[i]);
1418 dval(&da) = b2d(
a, &ka);
1419 dval(&db) = b2d(b, &kb);
1421 k = ka - kb + 32*(
a->wds - b->
wds);
1423 k = ka - kb + 16*(
a->wds - b->
wds);
1429 dval(&da) *= 1 <<
k;
1435 dval(&db) *= 1 <<
k;
1450 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
1451 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
1460bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
1461static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
1462#ifdef Avoid_Underflow
1463 9007199254740992.*9007199254740992.e-256
1471#define Scale_Bit 0x10
1475bigtens[] = { 1e16, 1e32, 1e64 };
1476static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64 };
1479bigtens[] = { 1e16, 1e32 };
1480static CONST double tinytens[] = { 1e-16, 1e-32 };
1500static unsigned char hexdig[256];
1503htinit(
unsigned char *h,
unsigned char *
s,
int inc)
1506 for(i = 0; (
j =
s[i]) !=0; i++)
1514#define USC (unsigned char *)
1515 htinit(hexdig, USC
"0123456789", 0x10);
1516 htinit(hexdig, USC
"abcdef", 0x10 + 10);
1517 htinit(hexdig, USC
"ABCDEF", 0x10 + 10);
1520static unsigned char hexdig[256] = {
1521 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1522 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1523 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1524 16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0,
1525 0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
1526 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1527 0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
1528 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1529 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1530 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1531 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1532 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1533 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1534 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1535 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1536 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
1544#define NAN_WORD0 0x7ff80000
1554 (
sp, t)
char **sp, *t;
1556 (
const char **
sp,
const char *t)
1563 if ((c = *++
s) >=
'A' && c <=
'Z')
1578 (
U *rvp,
const char **
sp)
1583 int c1, havedig, udx0, xshift;
1587 havedig = xshift = 0;
1591 while((c = *(
CONST unsigned char*)(
s+1)) && c <=
' ')
1593 if (
s[1] ==
'0' && (
s[2] ==
'x' ||
s[2] ==
'X'))
1595 while((c = *(
CONST unsigned char*)++
s)) {
1596 if ((c1 = hexdig[c]))
1598 else if (c <=
' ') {
1599 if (udx0 && havedig) {
1605#ifdef GDTOA_NON_PEDANTIC_NANCHECK
1606 else if ( c ==
')' && havedig) {
1619 }
while((c = *++
s));
1630 x[0] = (
x[0] << 4) | (
x[1] >> 28);
1631 x[1] = (
x[1] << 4) | c;
1633 if ((
x[0] &= 0xfffff) ||
x[1]) {
1651#if !defined(NO_HEX_FP) || defined(Honor_FLT_ROUNDS)
1665 if (*
x < (
ULong)0xffffffffL) {
1673 b1 = Balloc(b->
k+1);
1706 *x1++ = (
y | (*
x << n)) & 0xffffffff;
1716 if ((b->
wds = x1 - b->
x) == 0)
1735 else if (n < nwds && (
k &=
kmask)) {
1766 CONST unsigned char *decpt, *s0, *
s, *s1;
1769 int big, denorm, esign, havedig,
k, n, nbits, up, zret;
1775 emax = 0x7fe -
Bias -
P + 1,
1780 emax = 0x7ff -
Bias -
P + 1
1783 emax = 0x7f -
Bias -
P
1789#ifdef NO_LOCALE_CACHE
1790 const unsigned char *decimalpoint = (
unsigned char*)
1791 localeconv()->decimal_point;
1793 const unsigned char *decimalpoint;
1794 static unsigned char *decimalpoint_cache;
1795 if (!(s0 = decimalpoint_cache)) {
1796 s0 = (
unsigned char*)localeconv()->decimal_point;
1797 if ((decimalpoint_cache = (
unsigned char*)
1799 strcpy((
char*)decimalpoint_cache, (
CONST char*)s0);
1800 s0 = decimalpoint_cache;
1809 s0 = *(
CONST unsigned char **)sp + 2;
1810 while(s0[havedig] ==
'0')
1822 for(i = 0; decimalpoint[i]; ++i) {
1823 if (
s[i] != decimalpoint[i])
1844 if (*
s == *decimalpoint && !decpt) {
1845 for(i = 1; decimalpoint[i]; ++i) {
1846 if (
s[i] != decimalpoint[i])
1851 if (*
s ==
'.' && !decpt) {
1858 e = -(((
Long)(
s-decpt)) << 2);
1872 if ((n = hexdig[*
s]) == 0 || n > 0x19) {
1877 while((n = hexdig[*++
s]) !=0 && n <= 0x19) {
1878 if (e1 & 0xf8000000)
1880 e1 = 10*e1 + n - 0x10;
1888 *sp = (
char*)s0 - 1;
1936 for(
k = 0; n > (1 << (
kshift-2)) - 1; n >>= 1)
1943 for(i = 0; decimalpoint[i+1]; ++i);
1947 if (*--s1 == decimalpoint[i]) {
1960 L |= (hexdig[*s1] & 0x0f) << n;
1964 b->
wds = n =
x - b->
x;
1965 n =
ULbits*n - hi0bits(L);
1976 if (
k > 0 && any_on(b,
k))
1983 else if (n < nbits) {
2008 if (n == nbits && (n < 2 || any_on(b,n-1)))
2033 lostbits = any_on(b,
k);
2047 && (lostbits & 1) | (
x[0] & 1))
2062 if (nbits ==
Nbits - 1
2068 || ((n = nbits &
kmask) !=0
2069 && hi0bits(
x[
k-1]) < 32-n)) {
2078 word0(rvp) = b->
wds > 1 ? b->
x[1] & ~0x100000 : 0;
2080 word0(rvp) = (b->
x[1] & ~0x100000) | ((e + 0x3ff + 52) << 20);
2085 k = b->
x[0] & ((1 <<
j) - 1);
2099 if (
k &
j && ((
k & (
j-1)) | lostbits))
2105 word0(rvp) = b->
x[1] | ((e + 65 + 13) << 24);
2112 word0(rvp) = ((b->
x[1] & ~0x800000) >> 16) | ((e + 129 + 55) << 7) | (b->
x[1] << 16);
2113 word1(rvp) = (b->
x[0] >> 16) | (b->
x[0] << 16);
2121dshift(b, p2)
Bigint *b;
int p2;
2126 int rv = hi0bits(b->
x[b->
wds-1]) - 4;
2141 ULong *bx, *bxe, q, *sx, *sxe;
2143 ULLong borrow, carry, y, ys;
2145 ULong borrow, carry, y, ys;
2154 Bug(
"oversize b in quorem");
2162 q = *bxe / (*sxe + 1);
2164#ifdef NO_STRTOD_BIGCOMP
2171 Bug(
"oversized quotient in quorem");
2178 ys = *sx++ * (
ULLong)q + carry;
2180 y = *bx - (ys &
FFFFFFFF) - borrow;
2181 borrow = y >> 32 & (
ULong)1;
2186 ys = (si & 0xffff) * q + carry;
2187 zs = (si >> 16) * q + (ys >> 16);
2189 y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
2190 borrow = (y & 0x10000) >> 16;
2191 z = (*bx >> 16) - (zs & 0xffff) - borrow;
2192 borrow = (z & 0x10000) >> 16;
2195 ys = *sx++ * q + carry;
2197 y = *bx - (ys & 0xffff) - borrow;
2198 borrow = (y & 0x10000) >> 16;
2206 while(--bxe > bx && !*bxe)
2211 if (
cmp(b,
S) >= 0) {
2221 y = *bx - (ys &
FFFFFFFF) - borrow;
2222 borrow = y >> 32 & (
ULong)1;
2227 ys = (si & 0xffff) + carry;
2228 zs = (si >> 16) + (ys >> 16);
2230 y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
2231 borrow = (y & 0x10000) >> 16;
2232 z = (*bx >> 16) - (zs & 0xffff) - borrow;
2233 borrow = (z & 0x10000) >> 16;
2238 y = *bx - (ys & 0xffff) - borrow;
2239 borrow = (y & 0x10000) >> 16;
2248 while(--bxe > bx && !*bxe)
2256#if defined(Avoid_Underflow) || !defined(NO_STRTOD_BIGCOMP)
2278#ifndef NO_STRTOD_BIGCOMP
2289 int b2, bbits, d2, dd, dig, dsign, i,
j, nd, nd0, p2, p5, speccase;
2294 p5 = nd + bc->e0 - 1;
2296#ifndef Sudden_Underflow
2302#ifdef Avoid_Underflow
2308#ifdef Honor_FLT_ROUNDS
2309 if (bc->rounding == 1)
2320 b = d2b(
rv, &p2, &bbits);
2321#ifdef Avoid_Underflow
2327 if (i > (
j =
P -
Emin - 1 + p2)) {
2328#ifdef Sudden_Underflow
2333#ifdef Avoid_Underflow
2343#ifdef Honor_FLT_ROUNDS
2344 if (bc->rounding != 1) {
2356#ifndef Sudden_Underflow
2365 d = pow5mult(
d, p5);
2367 b = pow5mult(b, -p5);
2385 if (!(dig = quorem(b,
d))) {
2386 b = multadd(b, 10, 0);
2392 for(i = 0; i < nd0; ) {
2393 if ((dd = s0[i++] -
'0' - dig))
2395 if (!b->
x[0] && b->
wds == 1) {
2400 b = multadd(b, 10, 0);
2403 for(
j = bc->dp1; i++ < nd;) {
2404 if ((dd = s0[
j++] -
'0' - dig))
2406 if (!b->
x[0] && b->
wds == 1) {
2411 b = multadd(b, 10, 0);
2414 if (dig > 0 || b->
x[0] || b->
wds > 1)
2419#ifdef Honor_FLT_ROUNDS
2420 if (bc->rounding != 1) {
2422 if (bc->rounding == 0) {
2430 if (bc->rounding == 0) {
2470 else if (
word0(
rv) & (0x1 << (i-32)))
2481#ifdef Honor_FLT_ROUNDS
2491 (s00, se)
CONST char *s00;
char **se;
2493 (
const char *s00,
char **se)
2496 int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
2497 int esign, i,
j,
k, nd, nd0, nf, nz, nz0, nz1,
sign;
2501 U aadj2, adj,
rv, rv0;
2504 Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
2505#ifdef Avoid_Underflow
2511#ifndef NO_STRTOD_BIGCOMP
2512 int req_bigcomp = 0;
2514#ifdef Honor_FLT_ROUNDS
2515#ifdef Trust_FLT_ROUNDS
2519 switch(fegetround()) {
2520 case FE_TOWARDZERO: bc.
rounding = 0;
break;
2521 case FE_UPWARD: bc.
rounding = 2;
break;
2532 for(
s = s00;;
s++)
switch(*
s) {
2558#ifdef Honor_FLT_ROUNDS
2567 while(*++
s ==
'0') ;
2573 for(nd = nf = 0; (c = *
s) >=
'0' && c <=
'9'; nd++,
s++)
2576 else if (nd < DBL_DIG + 2)
2580 for(s1 =
s; s1 > s0 && *--s1 ==
'0'; )
2583 s1 = localeconv()->decimal_point;
2606 for(; c ==
'0'; c = *++
s)
2608 if (c >
'0' && c <=
'9') {
2618 for(; c >=
'0' && c <=
'9'; c = *++
s) {
2623 for(i = 1; i < nz; i++)
2626 else if (nd <= DBL_DIG + 2)
2630 else if (nd <= DBL_DIG + 2)
2638 if (c ==
'e' || c ==
'E') {
2639 if (!nd && !nz && !nz0) {
2650 if (c >=
'0' && c <=
'9') {
2653 if (c >
'0' && c <=
'9') {
2656 while((c = *++
s) >=
'0' && c <=
'9')
2658 if (
s - s1 > 8 || L > 19999)
2682 if (match(&
s,
"nf")) {
2684 if (!match(&
s,
"inity"))
2693 if (match(&
s,
"an")) {
2710 bc.
e0 = e1 = e -= nf;
2719 k = nd < DBL_DIG + 2 ? nd : DBL_DIG + 2;
2724 oldinexact = get_inexact();
2731#ifndef Honor_FLT_ROUNDS
2738#ifndef ROUND_BIASED_without_Round_Up
2742 goto vax_ovfl_check;
2744#ifdef Honor_FLT_ROUNDS
2760#ifdef Honor_FLT_ROUNDS
2786#ifndef Inaccurate_Divide
2788#ifdef Honor_FLT_ROUNDS
2807 oldinexact = get_inexact();
2809#ifdef Avoid_Underflow
2812#ifdef Honor_FLT_ROUNDS
2829 if (e1 > DBL_MAX_10_EXP) {
2833#ifdef Honor_FLT_ROUNDS
2871 for(
j = 0; e1 > 1;
j++, e1 >>= 1)
2897#ifdef Avoid_Underflow
2900 for(
j = 0; e1 > 0;
j++, e1 >>= 1)
2913 word0(&
rv) &= 0xffffffff << (
j-32);
2919 for(
j = 0; e1 > 1;
j++, e1 >>= 1)
2934#ifndef Avoid_Underflow
2950#ifndef NO_STRTOD_BIGCOMP
2974 for(i = 0; i < nd0; ++i)
2975 y = 10*y + s0[i] -
'0';
2976 for(
j = bc.
dp1; i < nd; ++i)
2977 y = 10*y + s0[
j++] -
'0';
2981 bd0 = s2b(s0, nd0, nd, y, bc.
dplen);
2984 bd = Balloc(bd0->
k);
2986 bb = d2b(&
rv, &bbe, &bbbits);
3002#ifdef Honor_FLT_ROUNDS
3006#ifdef Avoid_Underflow
3018 Lsb1 = Lsb << (i-32);
3023#ifdef Sudden_Underflow
3025 j = 1 + 4*
P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
3040#ifdef Avoid_Underflow
3043 i = bb2 < bd2 ? bb2 : bd2;
3052 bs = pow5mult(bs, bb5);
3058 bb = lshift(bb, bb2);
3060 bd = pow5mult(bd, bd5);
3062 bd = lshift(bd, bd2);
3064 bs = lshift(bs, bs2);
3065 delta =
diff(bb, bd);
3069#ifndef NO_STRTOD_BIGCOMP
3070 if (bc.
nd > nd && i <= 0) {
3076#ifdef Honor_FLT_ROUNDS
3088#ifdef Honor_FLT_ROUNDS
3092 if (!delta->
x[0] && delta->
wds <= 1) {
3105 else if (!bc.
dsign) {
3110#ifdef Avoid_Underflow
3116 delta = lshift(delta,
Log2P);
3117 if (
cmp(delta, bs) <= 0)
3122#ifdef Avoid_Underflow
3127#ifdef Sudden_Underflow
3141 adj.
d = ratio(delta, bs);
3144 if (adj.
d <= 0x7ffffffe) {
3153#ifdef Avoid_Underflow
3157#ifdef Sudden_Underflow
3188#ifdef Avoid_Underflow
3196 if (!delta->
x[0] && delta->
wds <= 1)
3201 if (!delta->
x[0] && delta->
wds <= 1) {
3208 delta = lshift(delta,
Log2P);
3209 if (
cmp(delta, bs) > 0)
3218#ifdef Avoid_Underflow
3220 ? (0xffffffff & (0xffffffff << (2*
P+1-(y>>
Exp_shift)))) :
3233#ifdef Avoid_Underflow
3242#ifdef Sudden_Underflow
3247#ifdef Avoid_Underflow
3262#ifdef Avoid_Underflow
3286#ifndef NO_STRTOD_BIGCOMP
3294#ifdef Avoid_Underflow
3307#ifdef Avoid_Underflow
3314#ifdef Avoid_Underflow
3319#ifndef Sudden_Underflow
3329#ifdef Avoid_Underflow
3335 if ((aadj = ratio(delta, bs)) <= 2.) {
3339#ifndef Sudden_Underflow
3355 if (aadj < 2./FLT_RADIX)
3356 aadj = 1./FLT_RADIX;
3364 aadj1 = bc.
dsign ? aadj : -aadj;
3365#ifdef Check_FLT_ROUNDS
3386 adj.
d = aadj1 * ulp(&
rv);
3400#ifdef Avoid_Underflow
3402 if (aadj <= 0x7fffffff) {
3403 if ((z = aadj) <= 0)
3406 aadj1 = bc.
dsign ? aadj : -aadj;
3408 dval(&aadj2) = aadj1;
3410 aadj1 =
dval(&aadj2);
3411 adj.
d = aadj1 * ulp(&
rv);
3414#ifdef NO_STRTOD_BIGCOMP
3424 adj.
d = aadj1 * ulp(&
rv);
3428#ifdef Sudden_Underflow
3432 adj.
d = aadj1 * ulp(&
rv);
3456 adj.
d = aadj1 * ulp(&
rv);
3468 aadj1 = (double)(
int)(aadj + 0.5);
3472 adj.
d = aadj1 * ulp(&
rv);
3480#ifdef Avoid_Underflow
3489 if (aadj < .4999999 || aadj > .5000001)
3492 else if (aadj < .4999999/FLT_RADIX)
3508#ifndef NO_STRTOD_BIGCOMP
3512 bigcomp(&
rv, s0, &bc);
3516 if (y == 0 &&
rv.d == 0.)
3528 else if (!oldinexact)
3531#ifdef Avoid_Underflow
3550 dval(&rv0) = 1e-300;
3560#ifndef MULTIPLE_THREADS
3561 static char *dtoa_result;
3578 r = (
int*)Balloc(
k);
3581#ifndef MULTIPLE_THREADS
3589nrv_alloc(
s, rve, n)
char *
s, **rve;
int n;
3591nrv_alloc(
const char *
s,
char **rve,
int n)
3596 t =
rv = rv_alloc(n);
3597 while((*t = *
s++)) t++;
3617 b->
maxwds = 1 << (b->
k = *(
int*)b);
3619#ifndef MULTIPLE_THREADS
3620 if (
s == dtoa_result)
3662 (dd, mode, ndigits, decpt,
sign, rve)
3663 double dd;
int mode, ndigits, *decpt, *
sign;
char **rve;
3665 (
double dd,
int mode,
int ndigits,
int *decpt,
int *
sign,
char **rve)
3702 int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
3703 j, j1,
k, k0, k_check, leftright, m2, m5, s2, s5,
3704 spec_case, try_quick;
3706#ifndef Sudden_Underflow
3710 Bigint *b, *b1, *delta, *mlo, *mhi, *
S;
3720 int inexact, oldinexact;
3722#ifdef Honor_FLT_ROUNDS
3724#ifdef Trust_FLT_ROUNDS
3728 switch(fegetround()) {
3729 case FE_TOWARDZERO: Rounding = 0;
break;
3730 case FE_UPWARD: Rounding = 2;
break;
3731 case FE_DOWNWARD: Rounding = 3;
3736#ifndef MULTIPLE_THREADS
3747 word0(&u) &= ~Sign_bit;
3752#if defined(IEEE_Arith) + defined(VAX)
3756 if (
word0(&u) == 0x8000)
3763 return nrv_alloc(
"Infinity", rve, 8);
3765 return nrv_alloc(
"NaN", rve, 3);
3773 return nrv_alloc(
"0", rve, 1);
3777 try_quick = oldinexact = get_inexact();
3780#ifdef Honor_FLT_ROUNDS
3781 if (Rounding >= 2) {
3783 Rounding = Rounding == 2 ? 0 : 2;
3790 b = d2b(&u, &be, &bbits);
3791#ifdef Sudden_Underflow
3801 dval(&d2) /= 1 <<
j;
3831#ifndef Sudden_Underflow
3837 i = bbits + be + (
Bias + (
P-1) - 1);
3838 x = i > 32 ?
word0(&u) << (64 - i) |
word1(&u) >> (i - 32)
3839 :
word1(&u) << (32 - i);
3842 i -= (
Bias + (
P-1) - 1) + 1;
3846 ds = (
dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
3848 if (ds < 0. && ds !=
k)
3852 if (
dval(&u) < tens[
k])
3875 if (mode < 0 || mode > 9)
3879#ifdef Check_FLT_ROUNDS
3880 try_quick = Rounding == 1;
3905 ilim = ilim1 = i = ndigits;
3911 i = ndigits +
k + 1;
3917 s = s0 = rv_alloc(i);
3919#ifdef Honor_FLT_ROUNDS
3920 if (mode > 1 && Rounding != 1)
3924 if (ilim >= 0 && ilim <=
Quick_max && try_quick) {
3942 for(;
j;
j >>= 1, i++)
3949 else if ((j1 = -
k)) {
3950 dval(&u) *= tens[j1 & 0xf];
3951 for(
j = j1 >> 4;
j;
j >>= 1, i++)
3954 dval(&u) *= bigtens[i];
3957 if (k_check &&
dval(&u) < 1. && ilim > 0) {
3981 dval(&eps) = 0.5/tens[ilim-1] -
dval(&eps);
3983 if (k0 < 0 && j1 >= 307) {
3986 dval(&eps1) *= tens[j1 & 0xf];
3987 for(i = 0,
j = (j1-256) >> 4;
j;
j >>= 1, i++)
3989 dval(&eps1) *= bigtens[i];
3997 *
s++ =
'0' + (int)L;
4011 dval(&eps) *= tens[ilim-1];
4012 for(i = 1;; i++,
dval(&u) *= 10.) {
4014 if (!(
dval(&u) -= L))
4016 *
s++ =
'0' + (int)L;
4020 else if (
dval(&u) < 0.5 -
dval(&eps)) {
4043 if (ndigits < 0 && ilim <= 0) {
4045 if (ilim < 0 ||
dval(&u) <= 5*ds)
4049 for(i = 1;; i++,
dval(&u) *= 10.) {
4052#ifdef Check_FLT_ROUNDS
4059 *
s++ =
'0' + (int)L;
4067#ifdef Honor_FLT_ROUNDS
4071 case 2:
goto bump_up;
4078 if (
dval(&u) > ds || (
dval(&u) == ds && L & 1))
4101#ifndef Sudden_Underflow
4102 denorm ? be + (
Bias + (
P-1) - 1 + 1) :
4105 1 + 4*
P - 3 - bbits + ((bbits + be - 1) & 3);
4113 if (m2 > 0 && s2 > 0) {
4114 i = m2 < s2 ? m2 : s2;
4122 mhi = pow5mult(mhi, m5);
4131 b = pow5mult(b, b5);
4135 S = pow5mult(
S, s5);
4140 if ((mode < 2 || leftright)
4141#ifdef Honor_FLT_ROUNDS
4175 b = multadd(b, 10, 0);
4177 mhi = multadd(mhi, 10, 0);
4181 if (ilim <= 0 && (mode == 3 || mode == 5)) {
4182 if (ilim < 0 ||
cmp(b,
S = multadd(
S,5,0)) <= 0) {
4195 mhi = lshift(mhi, m2);
4203 mhi = Balloc(mhi->
k);
4205 mhi = lshift(mhi,
Log2P);
4209 dig = quorem(b,
S) +
'0';
4214 delta =
diff(
S, mhi);
4215 j1 = delta->
sign ? 1 :
cmp(b, delta);
4218 if (j1 == 0 && mode != 1 && !(
word1(&u) & 1)
4219#ifdef Honor_FLT_ROUNDS
4228 else if (!b->
x[0] && b->
wds <= 1)
4235 if (
j < 0 || (
j == 0 && mode != 1
4240 if (!b->
x[0] && b->
wds <= 1) {
4246#ifdef Honor_FLT_ROUNDS
4249 case 0:
goto accept_dig;
4250 case 2:
goto keep_dig;
4259 if ((j1 > 0 || (j1 == 0 && dig & 1))
4269#ifdef Honor_FLT_ROUNDS
4281#ifdef Honor_FLT_ROUNDS
4287 b = multadd(b, 10, 0);
4289 mlo = mhi = multadd(mhi, 10, 0);
4291 mlo = multadd(mlo, 10, 0);
4292 mhi = multadd(mhi, 10, 0);
4298 *
s++ = dig = quorem(b,
S) +
'0';
4299 if (!b->
x[0] && b->
wds <= 1) {
4307 b = multadd(b, 10, 0);
4312#ifdef Honor_FLT_ROUNDS
4314 case 0:
goto trimzeros;
4315 case 2:
goto roundoff;
4323 if (
j > 0 || (
j == 0 && dig & 1))
4336#ifdef Honor_FLT_ROUNDS
4345 if (mlo && mlo != mhi)
4358 else if (!oldinexact)
#define rounded_product(a, b)
#define FREE_DTOA_LOCK(n)
#define rounded_quotient(a, b)
void gethex(CONST char **sp, U *rvp, int rounding, int sign)
Exactly one of IEEE_MC68k
#define Storeinc(a, b, c)
#define ACQUIRE_DTOA_LOCK(n)
void diff(const std::string &a, const std::string &b)
static const Reg16 sp(Operand::SP)
static const Opmask k1(1)
impl::ratio< uint64_t > ratio
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
#define S(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
void cmp(const Operand &op, uint32 imm)
void inc(const Operand &op)