OLD | NEW |
1 /**************************************************************** | 1 /**************************************************************** |
2 * | 2 * |
3 * The author of this software is David M. Gay. | 3 * The author of this software is David M. Gay. |
4 * | 4 * |
5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. | 5 * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. |
6 * | 6 * |
7 * Permission to use, copy, modify, and distribute this software for any | 7 * Permission to use, copy, modify, and distribute this software for any |
8 * purpose without fee is hereby granted, provided that this entire notice | 8 * purpose without fee is hereby granted, provided that this entire notice |
9 * is included in all copies of any software which is or includes a copy | 9 * is included in all copies of any software which is or includes a copy |
10 * or modification of this software and in all copies of the supporting | 10 * or modification of this software and in all copies of the supporting |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 { | 541 { |
542 int x; | 542 int x; |
543 Bigint *rv; | 543 Bigint *rv; |
544 #ifndef Omit_Private_Memory | 544 #ifndef Omit_Private_Memory |
545 unsigned int len; | 545 unsigned int len; |
546 #endif | 546 #endif |
547 | 547 |
548 ACQUIRE_DTOA_LOCK(0); | 548 ACQUIRE_DTOA_LOCK(0); |
549 /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */ | 549 /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */ |
550 /* but this case seems very unlikely. */ | 550 /* but this case seems very unlikely. */ |
551 » if (k <= Kmax && (rv = freelist[k])) | 551 » if (k <= Kmax && freelist[k]) { |
| 552 » » rv = freelist[k]; |
552 freelist[k] = rv->next; | 553 freelist[k] = rv->next; |
| 554 } |
553 else { | 555 else { |
554 x = 1 << k; | 556 x = 1 << k; |
555 #ifdef Omit_Private_Memory | 557 #ifdef Omit_Private_Memory |
556 rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong)); | 558 rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong)); |
557 #else | 559 #else |
558 len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1
) | 560 len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1
) |
559 /sizeof(double); | 561 /sizeof(double); |
560 if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { | 562 if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { |
561 rv = (Bigint*)pmem_next; | 563 rv = (Bigint*)pmem_next; |
562 pmem_next += len; | 564 pmem_next += len; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 c = Balloc(k); | 829 c = Balloc(k); |
828 for(x = c->x, xa = x + wc; x < xa; x++) | 830 for(x = c->x, xa = x + wc; x < xa; x++) |
829 *x = 0; | 831 *x = 0; |
830 xa = a->x; | 832 xa = a->x; |
831 xae = xa + wa; | 833 xae = xa + wa; |
832 xb = b->x; | 834 xb = b->x; |
833 xbe = xb + wb; | 835 xbe = xb + wb; |
834 xc0 = c->x; | 836 xc0 = c->x; |
835 #ifdef ULLong | 837 #ifdef ULLong |
836 for(; xb < xbe; xc0++) { | 838 for(; xb < xbe; xc0++) { |
837 » » if ((y = *xb++)) { | 839 » » y = *xb++; |
| 840 » » if (y) { |
838 x = xa; | 841 x = xa; |
839 xc = xc0; | 842 xc = xc0; |
840 carry = 0; | 843 carry = 0; |
841 do { | 844 do { |
842 z = *x++ * (ULLong)y + *xc + carry; | 845 z = *x++ * (ULLong)y + *xc + carry; |
843 carry = z >> 32; | 846 carry = z >> 32; |
844 *xc++ = z & FFFFFFFF; | 847 *xc++ = z & FFFFFFFF; |
845 } | 848 } |
846 while(x < xae); | 849 while(x < xae); |
847 *xc = carry; | 850 *xc = carry; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 #ifdef KR_headers | 912 #ifdef KR_headers |
910 (b, k) Bigint *b; int k; | 913 (b, k) Bigint *b; int k; |
911 #else | 914 #else |
912 (Bigint *b, int k) | 915 (Bigint *b, int k) |
913 #endif | 916 #endif |
914 { | 917 { |
915 Bigint *b1, *p5, *p51; | 918 Bigint *b1, *p5, *p51; |
916 int i; | 919 int i; |
917 static int p05[3] = { 5, 25, 125 }; | 920 static int p05[3] = { 5, 25, 125 }; |
918 | 921 |
919 » if ((i = k & 3)) | 922 » i = k & 3; |
| 923 » if (i) |
920 b = multadd(b, p05[i-1], 0); | 924 b = multadd(b, p05[i-1], 0); |
921 | 925 |
922 if (!(k >>= 2)) | 926 if (!(k >>= 2)) |
923 return b; | 927 return b; |
924 » if (!(p5 = p5s)) { | 928 » p5 = p5s; |
| 929 » if (!p5) { |
925 /* first time */ | 930 /* first time */ |
926 #ifdef MULTIPLE_THREADS | 931 #ifdef MULTIPLE_THREADS |
927 ACQUIRE_DTOA_LOCK(1); | 932 ACQUIRE_DTOA_LOCK(1); |
928 » » if (!(p5 = p5s)) { | 933 » » p5 = p5s; |
| 934 » » if (!p5) { |
929 p5 = p5s = i2b(625); | 935 p5 = p5s = i2b(625); |
930 p5->next = 0; | 936 p5->next = 0; |
931 } | 937 } |
932 FREE_DTOA_LOCK(1); | 938 FREE_DTOA_LOCK(1); |
933 #else | 939 #else |
934 p5 = p5s = i2b(625); | 940 p5 = p5s = i2b(625); |
935 p5->next = 0; | 941 p5->next = 0; |
936 #endif | 942 #endif |
937 } | 943 } |
938 for(;;) { | 944 for(;;) { |
939 if (k & 1) { | 945 if (k & 1) { |
940 b1 = mult(b, p5); | 946 b1 = mult(b, p5); |
941 Bfree(b); | 947 Bfree(b); |
942 b = b1; | 948 b = b1; |
943 } | 949 } |
944 if (!(k >>= 1)) | 950 if (!(k >>= 1)) |
945 break; | 951 break; |
946 » » if (!(p51 = p5->next)) { | 952 » » p51 = p5->next; |
| 953 » » if (!p51) { |
947 #ifdef MULTIPLE_THREADS | 954 #ifdef MULTIPLE_THREADS |
948 ACQUIRE_DTOA_LOCK(1); | 955 ACQUIRE_DTOA_LOCK(1); |
949 » » » if (!(p51 = p5->next)) { | 956 » » » p51 = p5->next; |
| 957 » » » if (!p51) { |
950 p51 = p5->next = mult(p5,p5); | 958 p51 = p5->next = mult(p5,p5); |
951 p51->next = 0; | 959 p51->next = 0; |
952 } | 960 } |
953 FREE_DTOA_LOCK(1); | 961 FREE_DTOA_LOCK(1); |
954 #else | 962 #else |
955 p51 = p5->next = mult(p5,p5); | 963 p51 = p5->next = mult(p5,p5); |
956 p51->next = 0; | 964 p51->next = 0; |
957 #endif | 965 #endif |
958 } | 966 } |
959 p5 = p51; | 967 p5 = p51; |
(...skipping 30 matching lines...) Expand all Loading... |
990 xe = x + b->wds; | 998 xe = x + b->wds; |
991 #ifdef Pack_32 | 999 #ifdef Pack_32 |
992 if (k &= 0x1f) { | 1000 if (k &= 0x1f) { |
993 k1 = 32 - k; | 1001 k1 = 32 - k; |
994 z = 0; | 1002 z = 0; |
995 do { | 1003 do { |
996 *x1++ = *x << k | z; | 1004 *x1++ = *x << k | z; |
997 z = *x++ >> k1; | 1005 z = *x++ >> k1; |
998 } | 1006 } |
999 while(x < xe); | 1007 while(x < xe); |
1000 » » if ((*x1 = z)) | 1008 » » *x1 = z; |
| 1009 » » if (*x1) |
1001 ++n1; | 1010 ++n1; |
1002 } | 1011 } |
1003 #else | 1012 #else |
1004 if (k &= 0xf) { | 1013 if (k &= 0xf) { |
1005 k1 = 16 - k; | 1014 k1 = 16 - k; |
1006 z = 0; | 1015 z = 0; |
1007 do { | 1016 do { |
1008 *x1++ = *x << k & 0xffff | z; | 1017 *x1++ = *x << k & 0xffff | z; |
1009 z = *x++ >> k1; | 1018 z = *x++ >> k1; |
1010 } | 1019 } |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 x = b->x; | 1301 x = b->x; |
1293 | 1302 |
1294 z = d0 & Frac_mask; | 1303 z = d0 & Frac_mask; |
1295 d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ | 1304 d0 &= 0x7fffffff; /* clear sign bit, which we ignore */ |
1296 #ifdef Sudden_Underflow | 1305 #ifdef Sudden_Underflow |
1297 de = (int)(d0 >> Exp_shift); | 1306 de = (int)(d0 >> Exp_shift); |
1298 #ifndef IBM | 1307 #ifndef IBM |
1299 z |= Exp_msk11; | 1308 z |= Exp_msk11; |
1300 #endif | 1309 #endif |
1301 #else | 1310 #else |
1302 » if ((de = (int)(d0 >> Exp_shift))) | 1311 » de = (int)(d0 >> Exp_shift); |
| 1312 » if (de) |
1303 z |= Exp_msk1; | 1313 z |= Exp_msk1; |
1304 #endif | 1314 #endif |
1305 #ifdef Pack_32 | 1315 #ifdef Pack_32 |
1306 » if ((y = d1)) { | 1316 » y = d1; |
1307 » » if ((k = lo0bits(&y))) { | 1317 » if (y) { |
| 1318 » » k = lo0bits(&y); |
| 1319 » » if (k) { |
1308 x[0] = y | z << (32 - k); | 1320 x[0] = y | z << (32 - k); |
1309 z >>= k; | 1321 z >>= k; |
1310 } | 1322 } |
1311 else | 1323 else |
1312 x[0] = y; | 1324 x[0] = y; |
| 1325 x[1] = z; |
| 1326 b->wds = x[1] ? 2 : 1; |
1313 #ifndef Sudden_Underflow | 1327 #ifndef Sudden_Underflow |
1314 » » i = | 1328 » » i = b->wds; |
1315 #endif | 1329 #endif |
1316 b->wds = (x[1] = z) ? 2 : 1; | |
1317 } | 1330 } |
1318 else { | 1331 else { |
1319 k = lo0bits(&z); | 1332 k = lo0bits(&z); |
1320 x[0] = z; | 1333 x[0] = z; |
1321 #ifndef Sudden_Underflow | 1334 #ifndef Sudden_Underflow |
1322 i = | 1335 i = |
1323 #endif | 1336 #endif |
1324 b->wds = 1; | 1337 b->wds = 1; |
1325 k += 32; | 1338 k += 32; |
1326 } | 1339 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 match | 1542 match |
1530 #ifdef KR_headers | 1543 #ifdef KR_headers |
1531 (sp, t) char **sp, *t; | 1544 (sp, t) char **sp, *t; |
1532 #else | 1545 #else |
1533 (CONST char **sp, CONST char *t) | 1546 (CONST char **sp, CONST char *t) |
1534 #endif | 1547 #endif |
1535 { | 1548 { |
1536 int c, d; | 1549 int c, d; |
1537 CONST char *s = *sp; | 1550 CONST char *s = *sp; |
1538 | 1551 |
1539 » while((d = *t++)) { | 1552 » for(d = *t++; d; d = *t++) { |
1540 if ((c = *++s) >= 'A' && c <= 'Z') | 1553 if ((c = *++s) >= 'A' && c <= 'Z') |
1541 c += 'a' - 'A'; | 1554 c += 'a' - 'A'; |
1542 if (c != d) | 1555 if (c != d) |
1543 return 0; | 1556 return 0; |
1544 } | 1557 } |
1545 *sp = s + 1; | 1558 *sp = s + 1; |
1546 return 1; | 1559 return 1; |
1547 } | 1560 } |
1548 | 1561 |
1549 #ifndef No_Hex_NaN | 1562 #ifndef No_Hex_NaN |
1550 static void | 1563 static void |
1551 hexnan | 1564 hexnan |
1552 #ifdef KR_headers | 1565 #ifdef KR_headers |
1553 (rvp, sp) U *rvp; CONST char **sp; | 1566 (rvp, sp) U *rvp; CONST char **sp; |
1554 #else | 1567 #else |
1555 (U *rvp, CONST char **sp) | 1568 (U *rvp, CONST char **sp) |
1556 #endif | 1569 #endif |
1557 { | 1570 { |
1558 ULong c, x[2]; | 1571 ULong c, x[2]; |
1559 CONST char *s; | 1572 CONST char *s; |
1560 int c1, havedig, udx0, xshift; | 1573 int c1, havedig, udx0, xshift; |
1561 | 1574 |
1562 if (!hexdig['0']) | 1575 if (!hexdig['0']) |
1563 hexdig_init(); | 1576 hexdig_init(); |
1564 x[0] = x[1] = 0; | 1577 x[0] = x[1] = 0; |
1565 havedig = xshift = 0; | 1578 havedig = xshift = 0; |
1566 udx0 = 1; | 1579 udx0 = 1; |
1567 s = *sp; | 1580 s = *sp; |
1568 /* allow optional initial 0x or 0X */ | 1581 /* allow optional initial 0x or 0X */ |
1569 » while((c = *(CONST unsigned char*)(s+1)) && c <= ' ') | 1582 » for(c = *(CONST unsigned char*)(s+1); c && c <= ' '; c = *(CONST unsigne
d char*)(s+1)) |
1570 ++s; | 1583 ++s; |
1571 if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')) | 1584 if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')) |
1572 s += 2; | 1585 s += 2; |
1573 » while((c = *(CONST unsigned char*)++s)) { | 1586 » for(c = *(CONST unsigned char*)++s; c; c = *(CONST unsigned char*)++s) { |
1574 » » if ((c1 = hexdig[c])) | 1587 » » c1 = hexdig[c]; |
| 1588 » » if (c1) |
1575 c = c1 & 0xf; | 1589 c = c1 & 0xf; |
1576 else if (c <= ' ') { | 1590 else if (c <= ' ') { |
1577 if (udx0 && havedig) { | 1591 if (udx0 && havedig) { |
1578 udx0 = 0; | 1592 udx0 = 0; |
1579 xshift = 1; | 1593 xshift = 1; |
1580 } | 1594 } |
1581 continue; | 1595 continue; |
1582 } | 1596 } |
1583 #ifdef GDTOA_NON_PEDANTIC_NANCHECK | 1597 #ifdef GDTOA_NON_PEDANTIC_NANCHECK |
1584 else if (/*(*/ c == ')' && havedig) { | 1598 else if (/*(*/ c == ')' && havedig) { |
1585 *sp = s + 1; | 1599 *sp = s + 1; |
1586 break; | 1600 break; |
1587 } | 1601 } |
1588 else | 1602 else |
1589 return; /* invalid form: don't change *sp */ | 1603 return; /* invalid form: don't change *sp */ |
1590 #else | 1604 #else |
1591 else { | 1605 else { |
1592 do { | 1606 do { |
1593 if (/*(*/ c == ')') { | 1607 if (/*(*/ c == ')') { |
1594 *sp = s + 1; | 1608 *sp = s + 1; |
1595 break; | 1609 break; |
1596 } | 1610 } |
1597 » » » » } while((c = *++s)); | 1611 » » » » c = *++s; |
| 1612 » » » » } while(c); |
1598 break; | 1613 break; |
1599 } | 1614 } |
1600 #endif | 1615 #endif |
1601 havedig = 1; | 1616 havedig = 1; |
1602 if (xshift) { | 1617 if (xshift) { |
1603 xshift = 0; | 1618 xshift = 0; |
1604 x[0] = x[1]; | 1619 x[0] = x[1]; |
1605 x[1] = 0; | 1620 x[1] = 0; |
1606 } | 1621 } |
1607 if (udx0) | 1622 if (udx0) |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2321 } | 2336 } |
2322 i = dshift(d, d2); | 2337 i = dshift(d, d2); |
2323 if ((b2 += i) > 0) | 2338 if ((b2 += i) > 0) |
2324 b = lshift(b, b2); | 2339 b = lshift(b, b2); |
2325 if ((d2 += i) > 0) | 2340 if ((d2 += i) > 0) |
2326 d = lshift(d, d2); | 2341 d = lshift(d, d2); |
2327 | 2342 |
2328 /* Now b/d = exactly half-way between the two floating-point values */ | 2343 /* Now b/d = exactly half-way between the two floating-point values */ |
2329 /* on either side of the input string. Compute first digit of b/d. */ | 2344 /* on either side of the input string. Compute first digit of b/d. */ |
2330 | 2345 |
2331 » if (!(dig = quorem(b,d))) { | 2346 » dig = quorem(b,d); |
| 2347 » if (!dig) { |
2332 b = multadd(b, 10, 0); /* very unlikely */ | 2348 b = multadd(b, 10, 0); /* very unlikely */ |
2333 dig = quorem(b,d); | 2349 dig = quorem(b,d); |
2334 } | 2350 } |
2335 | 2351 |
2336 /* Compare b/d with s0 */ | 2352 /* Compare b/d with s0 */ |
2337 | 2353 |
2338 for(i = 0; i < nd0; ) { | 2354 for(i = 0; i < nd0; ) { |
2339 » » if ((dd = s0[i++] - '0' - dig)) | 2355 » » dd = s0[i++] - '0' - dig; |
| 2356 » » if (dd) |
2340 goto ret; | 2357 goto ret; |
2341 if (!b->x[0] && b->wds == 1) { | 2358 if (!b->x[0] && b->wds == 1) { |
2342 if (i < nd) | 2359 if (i < nd) |
2343 dd = 1; | 2360 dd = 1; |
2344 goto ret; | 2361 goto ret; |
2345 } | 2362 } |
2346 b = multadd(b, 10, 0); | 2363 b = multadd(b, 10, 0); |
2347 dig = quorem(b,d); | 2364 dig = quorem(b,d); |
2348 } | 2365 } |
2349 for(j = bc->dp1; i++ < nd;) { | 2366 for(j = bc->dp1; i++ < nd;) { |
2350 » » if ((dd = s0[j++] - '0' - dig)) | 2367 » » dd = s0[j++] - '0' - dig; |
| 2368 » » if (dd) |
2351 goto ret; | 2369 goto ret; |
2352 if (!b->x[0] && b->wds == 1) { | 2370 if (!b->x[0] && b->wds == 1) { |
2353 if (i < nd) | 2371 if (i < nd) |
2354 dd = 1; | 2372 dd = 1; |
2355 goto ret; | 2373 goto ret; |
2356 } | 2374 } |
2357 b = multadd(b, 10, 0); | 2375 b = multadd(b, 10, 0); |
2358 dig = quorem(b,d); | 2376 dig = quorem(b,d); |
2359 } | 2377 } |
2360 if (b->x[0] || b->wds > 1) | 2378 if (b->x[0] || b->wds > 1) |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2740 else | 2758 else |
2741 if (bc.rounding != 2) | 2759 if (bc.rounding != 2) |
2742 bc.rounding = 0; | 2760 bc.rounding = 0; |
2743 } | 2761 } |
2744 #endif | 2762 #endif |
2745 #endif /*IEEE_Arith*/ | 2763 #endif /*IEEE_Arith*/ |
2746 | 2764 |
2747 /* Get starting approximation = rv * 10**e1 */ | 2765 /* Get starting approximation = rv * 10**e1 */ |
2748 | 2766 |
2749 if (e1 > 0) { | 2767 if (e1 > 0) { |
2750 » » if ((i = e1 & 15)) | 2768 » » i = e1 & 15; |
| 2769 » » if (i) |
2751 dval(&rv) *= tens[i]; | 2770 dval(&rv) *= tens[i]; |
2752 if (e1 &= ~15) { | 2771 if (e1 &= ~15) { |
2753 if (e1 > DBL_MAX_10_EXP) { | 2772 if (e1 > DBL_MAX_10_EXP) { |
2754 ovfl: | 2773 ovfl: |
2755 #ifndef NO_ERRNO | 2774 #ifndef NO_ERRNO |
2756 errno = ERANGE; | 2775 errno = ERANGE; |
2757 #endif | 2776 #endif |
2758 /* Can't trust HUGE_VAL */ | 2777 /* Can't trust HUGE_VAL */ |
2759 #ifdef IEEE_Arith | 2778 #ifdef IEEE_Arith |
2760 #ifdef Honor_FLT_ROUNDS | 2779 #ifdef Honor_FLT_ROUNDS |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2798 /* (Can't trust DBL_MAX) */ | 2817 /* (Can't trust DBL_MAX) */ |
2799 word0(&rv) = Big0; | 2818 word0(&rv) = Big0; |
2800 word1(&rv) = Big1; | 2819 word1(&rv) = Big1; |
2801 } | 2820 } |
2802 else | 2821 else |
2803 word0(&rv) += P*Exp_msk1; | 2822 word0(&rv) += P*Exp_msk1; |
2804 } | 2823 } |
2805 } | 2824 } |
2806 else if (e1 < 0) { | 2825 else if (e1 < 0) { |
2807 e1 = -e1; | 2826 e1 = -e1; |
2808 » » if ((i = e1 & 15)) | 2827 » » i = e1 & 15; |
| 2828 » » if (i) |
2809 dval(&rv) /= tens[i]; | 2829 dval(&rv) /= tens[i]; |
2810 if (e1 >>= 4) { | 2830 if (e1 >>= 4) { |
2811 if (e1 >= 1 << n_bigtens) | 2831 if (e1 >= 1 << n_bigtens) |
2812 goto undfl; | 2832 goto undfl; |
2813 #ifdef Avoid_Underflow | 2833 #ifdef Avoid_Underflow |
2814 if (e1 & Scale_Bit) | 2834 if (e1 & Scale_Bit) |
2815 bc.scale = 2*P; | 2835 bc.scale = 2*P; |
2816 for(j = 0; e1 > 0; j++, e1 >>= 1) | 2836 for(j = 0; e1 > 0; j++, e1 >>= 1) |
2817 if (e1 & 1) | 2837 if (e1 & 1) |
2818 dval(&rv) *= tinytens[j]; | 2838 dval(&rv) *= tinytens[j]; |
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3449 static char * | 3469 static char * |
3450 #ifdef KR_headers | 3470 #ifdef KR_headers |
3451 nrv_alloc(s, rve, n) char *s, **rve; int n; | 3471 nrv_alloc(s, rve, n) char *s, **rve; int n; |
3452 #else | 3472 #else |
3453 nrv_alloc(CONST char *s, char **rve, int n) | 3473 nrv_alloc(CONST char *s, char **rve, int n) |
3454 #endif | 3474 #endif |
3455 { | 3475 { |
3456 char *rv, *t; | 3476 char *rv, *t; |
3457 | 3477 |
3458 t = rv = rv_alloc(n); | 3478 t = rv = rv_alloc(n); |
3459 » while((*t = *s++)) t++; | 3479 » for(*t = *s++; *t; *t = *s++) t++; |
3460 if (rve) | 3480 if (rve) |
3461 *rve = t; | 3481 *rve = t; |
3462 return rv; | 3482 return rv; |
3463 } | 3483 } |
3464 | 3484 |
3465 /* freedtoa(s) must be used to free values s returned by dtoa | 3485 /* freedtoa(s) must be used to free values s returned by dtoa |
3466 * when MULTIPLE_THREADS is #defined. It should be used in all cases, | 3486 * when MULTIPLE_THREADS is #defined. It should be used in all cases, |
3467 * but for consistency with earlier versions of dtoa, it is optional | 3487 * but for consistency with earlier versions of dtoa, it is optional |
3468 * when MULTIPLE_THREADS is not defined. | 3488 * when MULTIPLE_THREADS is not defined. |
3469 */ | 3489 */ |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3638 if (Rounding >= 2) { | 3658 if (Rounding >= 2) { |
3639 if (*sign) | 3659 if (*sign) |
3640 Rounding = Rounding == 2 ? 0 : 2; | 3660 Rounding = Rounding == 2 ? 0 : 2; |
3641 else | 3661 else |
3642 if (Rounding != 2) | 3662 if (Rounding != 2) |
3643 Rounding = 0; | 3663 Rounding = 0; |
3644 } | 3664 } |
3645 #endif | 3665 #endif |
3646 | 3666 |
3647 b = d2b(&u, &be, &bbits); | 3667 b = d2b(&u, &be, &bbits); |
3648 #ifdef Sudden_Underflow | |
3649 i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); | 3668 i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); |
3650 #else | 3669 #ifndef Sudden_Underflow |
3651 » if ((i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)))) { | 3670 » if (i) { |
3652 #endif | 3671 #endif |
3653 dval(&d2) = dval(&u); | 3672 dval(&d2) = dval(&u); |
3654 word0(&d2) &= Frac_mask1; | 3673 word0(&d2) &= Frac_mask1; |
3655 word0(&d2) |= Exp_11; | 3674 word0(&d2) |= Exp_11; |
3656 #ifdef IBM | 3675 #ifdef IBM |
3657 if (j = 11 - hi0bits(word0(&d2) & Frac_mask)) | 3676 if (j = 11 - hi0bits(word0(&d2) & Frac_mask)) |
3658 dval(&d2) /= 1 << j; | 3677 dval(&d2) /= 1 << j; |
3659 #endif | 3678 #endif |
3660 | 3679 |
3661 /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 | 3680 /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3796 dval(&u) /= bigtens[n_bigtens-1]; | 3815 dval(&u) /= bigtens[n_bigtens-1]; |
3797 ieps++; | 3816 ieps++; |
3798 } | 3817 } |
3799 for(; j; j >>= 1, i++) | 3818 for(; j; j >>= 1, i++) |
3800 if (j & 1) { | 3819 if (j & 1) { |
3801 ieps++; | 3820 ieps++; |
3802 ds *= bigtens[i]; | 3821 ds *= bigtens[i]; |
3803 } | 3822 } |
3804 dval(&u) /= ds; | 3823 dval(&u) /= ds; |
3805 } | 3824 } |
3806 » » else if ((j1 = -k)) { | 3825 » » else { |
3807 » » » dval(&u) *= tens[j1 & 0xf]; | 3826 » » » j1 = -k; |
3808 » » » for(j = j1 >> 4; j; j >>= 1, i++) | 3827 » » » if (j1) { |
3809 » » » » if (j & 1) { | 3828 » » » » dval(&u) *= tens[j1 & 0xf]; |
3810 » » » » » ieps++; | 3829 » » » » for(j = j1 >> 4; j; j >>= 1, i++) |
3811 » » » » » dval(&u) *= bigtens[i]; | 3830 » » » » » if (j & 1) { |
3812 » » » » » } | 3831 » » » » » » ieps++; |
| 3832 » » » » » » dval(&u) *= bigtens[i]; |
| 3833 » » » » » » } |
| 3834 » » » » } |
3813 } | 3835 } |
3814 if (k_check && dval(&u) < 1. && ilim > 0) { | 3836 if (k_check && dval(&u) < 1. && ilim > 0) { |
3815 if (ilim1 <= 0) | 3837 if (ilim1 <= 0) |
3816 goto fast_failed; | 3838 goto fast_failed; |
3817 ilim = ilim1; | 3839 ilim = ilim1; |
3818 k--; | 3840 k--; |
3819 dval(&u) *= 10.; | 3841 dval(&u) *= 10.; |
3820 ieps++; | 3842 ieps++; |
3821 } | 3843 } |
3822 dval(&eps) = ieps*dval(&u) + 7.; | 3844 dval(&eps) = ieps*dval(&u) + 7.; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3957 s2 -= i; | 3979 s2 -= i; |
3958 } | 3980 } |
3959 if (b5 > 0) { | 3981 if (b5 > 0) { |
3960 if (leftright) { | 3982 if (leftright) { |
3961 if (m5 > 0) { | 3983 if (m5 > 0) { |
3962 mhi = pow5mult(mhi, m5); | 3984 mhi = pow5mult(mhi, m5); |
3963 b1 = mult(mhi, b); | 3985 b1 = mult(mhi, b); |
3964 Bfree(b); | 3986 Bfree(b); |
3965 b = b1; | 3987 b = b1; |
3966 } | 3988 } |
3967 » » » if ((j = b5 - m5)) | 3989 » » » j = b5 - m5; |
| 3990 » » » if (j) |
3968 b = pow5mult(b, j); | 3991 b = pow5mult(b, j); |
3969 } | 3992 } |
3970 else | 3993 else |
3971 b = pow5mult(b, b5); | 3994 b = pow5mult(b, b5); |
3972 } | 3995 } |
3973 S = i2b(1); | 3996 S = i2b(1); |
3974 if (s5 > 0) | 3997 if (s5 > 0) |
3975 S = pow5mult(S, s5); | 3998 S = pow5mult(S, s5); |
3976 | 3999 |
3977 /* Check for special case that d is a normalized power of 2. */ | 4000 /* Check for special case that d is a normalized power of 2. */ |
(...skipping 17 matching lines...) Expand all Loading... |
3995 } | 4018 } |
3996 | 4019 |
3997 /* Arrange for convenient computation of quotients: | 4020 /* Arrange for convenient computation of quotients: |
3998 * shift left if necessary so divisor has 4 leading 0 bits. | 4021 * shift left if necessary so divisor has 4 leading 0 bits. |
3999 * | 4022 * |
4000 * Perhaps we should just compute leading 28 bits of S once | 4023 * Perhaps we should just compute leading 28 bits of S once |
4001 * and for all and pass them and a shift to quorem, so it | 4024 * and for all and pass them and a shift to quorem, so it |
4002 * can do shifts and ors to compute the numerator for q. | 4025 * can do shifts and ors to compute the numerator for q. |
4003 */ | 4026 */ |
4004 #ifdef Pack_32 | 4027 #ifdef Pack_32 |
4005 » if ((i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f)) | 4028 » i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f; |
| 4029 » if (i) |
4006 i = 32 - i; | 4030 i = 32 - i; |
4007 #define iInc 28 | 4031 #define iInc 28 |
4008 #else | 4032 #else |
4009 if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) | 4033 if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) |
4010 i = 16 - i; | 4034 i = 16 - i; |
4011 #define iInc 12 | 4035 #define iInc 12 |
4012 #endif | 4036 #endif |
4013 i = dshift(S, s2); | 4037 i = dshift(S, s2); |
4014 b2 += i; | 4038 b2 += i; |
4015 m2 += i; | 4039 m2 += i; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4200 #endif | 4224 #endif |
4201 Bfree(b); | 4225 Bfree(b); |
4202 *s = 0; | 4226 *s = 0; |
4203 *decpt = k + 1; | 4227 *decpt = k + 1; |
4204 if (rve) | 4228 if (rve) |
4205 *rve = s; | 4229 *rve = s; |
4206 return s0; | 4230 return s0; |
4207 } | 4231 } |
4208 | 4232 |
4209 } // namespace dmg_fp | 4233 } // namespace dmg_fp |
OLD | NEW |