diff options
Diffstat (limited to 'src/lib/libc/stdlib/strtod.c')
-rw-r--r-- | src/lib/libc/stdlib/strtod.c | 404 |
1 files changed, 158 insertions, 246 deletions
diff --git a/src/lib/libc/stdlib/strtod.c b/src/lib/libc/stdlib/strtod.c index b13fa128f5..94eca88659 100644 --- a/src/lib/libc/stdlib/strtod.c +++ b/src/lib/libc/stdlib/strtod.c | |||
@@ -79,7 +79,6 @@ | |||
79 | * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision | 79 | * #define Just_16 to store 16 bits per 32-bit Long when doing high-precision |
80 | * integer arithmetic. Whether this speeds things up or slows things | 80 | * integer arithmetic. Whether this speeds things up or slows things |
81 | * down depends on the machine and the number being converted. | 81 | * down depends on the machine and the number being converted. |
82 | * #define KR_headers for old-style C function headers. | ||
83 | * #define Bad_float_h if your system lacks a float.h or if it does not | 82 | * #define Bad_float_h if your system lacks a float.h or if it does not |
84 | * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, | 83 | * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP, |
85 | * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. | 84 | * FLT_RADIX, FLT_ROUNDS, and DBL_MAX. |
@@ -90,12 +89,14 @@ | |||
90 | */ | 89 | */ |
91 | 90 | ||
92 | #if defined(LIBC_SCCS) && !defined(lint) | 91 | #if defined(LIBC_SCCS) && !defined(lint) |
93 | static char *rcsid = "$Id: strtod.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $"; | 92 | static char *rcsid = "$OpenBSD: strtod.c,v 1.20 2005/03/30 18:51:49 pat Exp $"; |
94 | #endif /* LIBC_SCCS and not lint */ | 93 | #endif /* LIBC_SCCS and not lint */ |
95 | 94 | ||
96 | #if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ | 95 | #if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \ |
97 | defined(__mips__) || defined(__ns32k__) || defined(__alpha__) | 96 | defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \ |
98 | #include <machine/endian.h> | 97 | defined(__powerpc__) || defined(__m88k__) || defined(__hppa__) || \ |
98 | defined(__x86_64__) || (defined(__arm__) && defined(__VFP_FP__)) | ||
99 | #include <sys/types.h> | ||
99 | #if BYTE_ORDER == BIG_ENDIAN | 100 | #if BYTE_ORDER == BIG_ENDIAN |
100 | #define IEEE_BIG_ENDIAN | 101 | #define IEEE_BIG_ENDIAN |
101 | #else | 102 | #else |
@@ -103,7 +104,16 @@ static char *rcsid = "$Id: strtod.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $" | |||
103 | #endif | 104 | #endif |
104 | #endif | 105 | #endif |
105 | 106 | ||
106 | #ifdef vax | 107 | #if defined(__arm__) && !defined(__VFP_FP__) |
108 | /* | ||
109 | * Although the CPU is little endian the FP has different | ||
110 | * byte and word endianness. The byte order is still little endian | ||
111 | * but the word order is big endian. | ||
112 | */ | ||
113 | #define IEEE_BIG_ENDIAN | ||
114 | #endif | ||
115 | |||
116 | #ifdef __vax__ | ||
107 | #define VAX | 117 | #define VAX |
108 | #endif | 118 | #endif |
109 | 119 | ||
@@ -119,22 +129,13 @@ static char *rcsid = "$Id: strtod.c,v 1.1.1.1 1995/10/18 08:42:19 deraadt Exp $" | |||
119 | #include "malloc.h" | 129 | #include "malloc.h" |
120 | #include "memory.h" | 130 | #include "memory.h" |
121 | #else | 131 | #else |
122 | #ifndef KR_headers | ||
123 | #include "stdlib.h" | 132 | #include "stdlib.h" |
124 | #include "string.h" | 133 | #include "string.h" |
125 | #include "locale.h" | 134 | #include "locale.h" |
126 | #else | ||
127 | #include "malloc.h" | ||
128 | #include "memory.h" | ||
129 | #endif | ||
130 | #endif | 135 | #endif |
131 | 136 | ||
132 | #ifdef MALLOC | 137 | #ifdef MALLOC |
133 | #ifdef KR_headers | ||
134 | extern char *MALLOC(); | ||
135 | #else | ||
136 | extern void *MALLOC(size_t); | 138 | extern void *MALLOC(size_t); |
137 | #endif | ||
138 | #else | 139 | #else |
139 | #define MALLOC malloc | 140 | #define MALLOC malloc |
140 | #endif | 141 | #endif |
@@ -143,7 +144,6 @@ extern void *MALLOC(size_t); | |||
143 | #include "errno.h" | 144 | #include "errno.h" |
144 | 145 | ||
145 | #ifdef Bad_float_h | 146 | #ifdef Bad_float_h |
146 | #undef __STDC__ | ||
147 | #ifdef IEEE_BIG_ENDIAN | 147 | #ifdef IEEE_BIG_ENDIAN |
148 | #define IEEE_ARITHMETIC | 148 | #define IEEE_ARITHMETIC |
149 | #endif | 149 | #endif |
@@ -193,12 +193,8 @@ extern "C" { | |||
193 | #endif | 193 | #endif |
194 | 194 | ||
195 | #ifndef CONST | 195 | #ifndef CONST |
196 | #ifdef KR_headers | ||
197 | #define CONST /* blank */ | ||
198 | #else | ||
199 | #define CONST const | 196 | #define CONST const |
200 | #endif | 197 | #endif |
201 | #endif | ||
202 | 198 | ||
203 | #ifdef Unsigned_Shifts | 199 | #ifdef Unsigned_Shifts |
204 | #define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; | 200 | #define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; |
@@ -212,19 +208,24 @@ Exactly one of IEEE_LITTLE_ENDIAN IEEE_BIG_ENDIAN, VAX, or | |||
212 | IBM should be defined. | 208 | IBM should be defined. |
213 | #endif | 209 | #endif |
214 | 210 | ||
211 | typedef union { | ||
212 | double d; | ||
213 | ULong ul[2]; | ||
214 | } _double; | ||
215 | #define value(x) ((x).d) | ||
215 | #ifdef IEEE_LITTLE_ENDIAN | 216 | #ifdef IEEE_LITTLE_ENDIAN |
216 | #define word0(x) ((ULong *)&x)[1] | 217 | #define word0(x) ((x).ul[1]) |
217 | #define word1(x) ((ULong *)&x)[0] | 218 | #define word1(x) ((x).ul[0]) |
218 | #else | 219 | #else |
219 | #define word0(x) ((ULong *)&x)[0] | 220 | #define word0(x) ((x).ul[0]) |
220 | #define word1(x) ((ULong *)&x)[1] | 221 | #define word1(x) ((x).ul[1]) |
221 | #endif | 222 | #endif |
222 | 223 | ||
223 | /* The following definition of Storeinc is appropriate for MIPS processors. | 224 | /* The following definition of Storeinc is appropriate for MIPS processors. |
224 | * An alternative that might be better on some machines is | 225 | * An alternative that might be better on some machines is |
225 | * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) | 226 | * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff) |
226 | */ | 227 | */ |
227 | #if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) | 228 | #if defined(IEEE_LITTLE_ENDIAN) + defined(VAX) + defined(__arm__) |
228 | #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ | 229 | #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \ |
229 | ((unsigned short *)a)[0] = (unsigned short)c, a++) | 230 | ((unsigned short *)a)[0] = (unsigned short)c, a++) |
230 | #else | 231 | #else |
@@ -326,11 +327,7 @@ IBM should be defined. | |||
326 | #ifdef RND_PRODQUOT | 327 | #ifdef RND_PRODQUOT |
327 | #define rounded_product(a,b) a = rnd_prod(a, b) | 328 | #define rounded_product(a,b) a = rnd_prod(a, b) |
328 | #define rounded_quotient(a,b) a = rnd_quot(a, b) | 329 | #define rounded_quotient(a,b) a = rnd_quot(a, b) |
329 | #ifdef KR_headers | ||
330 | extern double rnd_prod(), rnd_quot(); | ||
331 | #else | ||
332 | extern double rnd_prod(double, double), rnd_quot(double, double); | 330 | extern double rnd_prod(double, double), rnd_quot(double, double); |
333 | #endif | ||
334 | #else | 331 | #else |
335 | #define rounded_product(a,b) a *= b | 332 | #define rounded_product(a,b) a *= b |
336 | #define rounded_quotient(a,b) a /= b | 333 | #define rounded_quotient(a,b) a /= b |
@@ -370,17 +367,12 @@ Bigint { | |||
370 | static Bigint *freelist[Kmax+1]; | 367 | static Bigint *freelist[Kmax+1]; |
371 | 368 | ||
372 | static Bigint * | 369 | static Bigint * |
373 | Balloc | 370 | Balloc(int k) |
374 | #ifdef KR_headers | ||
375 | (k) int k; | ||
376 | #else | ||
377 | (int k) | ||
378 | #endif | ||
379 | { | 371 | { |
380 | int x; | 372 | int x; |
381 | Bigint *rv; | 373 | Bigint *rv; |
382 | 374 | ||
383 | if (rv = freelist[k]) { | 375 | if ((rv = freelist[k])) { |
384 | freelist[k] = rv->next; | 376 | freelist[k] = rv->next; |
385 | } | 377 | } |
386 | else { | 378 | else { |
@@ -394,12 +386,7 @@ Balloc | |||
394 | } | 386 | } |
395 | 387 | ||
396 | static void | 388 | static void |
397 | Bfree | 389 | Bfree(Bigint *v) |
398 | #ifdef KR_headers | ||
399 | (v) Bigint *v; | ||
400 | #else | ||
401 | (Bigint *v) | ||
402 | #endif | ||
403 | { | 390 | { |
404 | if (v) { | 391 | if (v) { |
405 | v->next = freelist[v->k]; | 392 | v->next = freelist[v->k]; |
@@ -411,12 +398,7 @@ Bfree | |||
411 | y->wds*sizeof(Long) + 2*sizeof(int)) | 398 | y->wds*sizeof(Long) + 2*sizeof(int)) |
412 | 399 | ||
413 | static Bigint * | 400 | static Bigint * |
414 | multadd | 401 | multadd(Bigint *b, int m, int a) /* multiply by m and add a */ |
415 | #ifdef KR_headers | ||
416 | (b, m, a) Bigint *b; int m, a; | ||
417 | #else | ||
418 | (Bigint *b, int m, int a) /* multiply by m and add a */ | ||
419 | #endif | ||
420 | { | 402 | { |
421 | int i, wds; | 403 | int i, wds; |
422 | ULong *x, y; | 404 | ULong *x, y; |
@@ -456,12 +438,7 @@ multadd | |||
456 | } | 438 | } |
457 | 439 | ||
458 | static Bigint * | 440 | static Bigint * |
459 | s2b | 441 | s2b(CONST char *s, int nd0, int nd, ULong y9) |
460 | #ifdef KR_headers | ||
461 | (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; | ||
462 | #else | ||
463 | (CONST char *s, int nd0, int nd, ULong y9) | ||
464 | #endif | ||
465 | { | 442 | { |
466 | Bigint *b; | 443 | Bigint *b; |
467 | int i, k; | 444 | int i, k; |
@@ -494,14 +471,9 @@ s2b | |||
494 | } | 471 | } |
495 | 472 | ||
496 | static int | 473 | static int |
497 | hi0bits | 474 | hi0bits(ULong x) |
498 | #ifdef KR_headers | ||
499 | (x) register ULong x; | ||
500 | #else | ||
501 | (register ULong x) | ||
502 | #endif | ||
503 | { | 475 | { |
504 | register int k = 0; | 476 | int k = 0; |
505 | 477 | ||
506 | if (!(x & 0xffff0000)) { | 478 | if (!(x & 0xffff0000)) { |
507 | k = 16; | 479 | k = 16; |
@@ -528,15 +500,10 @@ hi0bits | |||
528 | } | 500 | } |
529 | 501 | ||
530 | static int | 502 | static int |
531 | lo0bits | 503 | lo0bits(ULong *y) |
532 | #ifdef KR_headers | ||
533 | (y) ULong *y; | ||
534 | #else | ||
535 | (ULong *y) | ||
536 | #endif | ||
537 | { | 504 | { |
538 | register int k; | 505 | int k; |
539 | register ULong x = *y; | 506 | ULong x = *y; |
540 | 507 | ||
541 | if (x & 7) { | 508 | if (x & 7) { |
542 | if (x & 1) | 509 | if (x & 1) |
@@ -576,12 +543,7 @@ lo0bits | |||
576 | } | 543 | } |
577 | 544 | ||
578 | static Bigint * | 545 | static Bigint * |
579 | i2b | 546 | i2b(int i) |
580 | #ifdef KR_headers | ||
581 | (i) int i; | ||
582 | #else | ||
583 | (int i) | ||
584 | #endif | ||
585 | { | 547 | { |
586 | Bigint *b; | 548 | Bigint *b; |
587 | 549 | ||
@@ -592,12 +554,7 @@ i2b | |||
592 | } | 554 | } |
593 | 555 | ||
594 | static Bigint * | 556 | static Bigint * |
595 | mult | 557 | mult(Bigint *a, Bigint *b) |
596 | #ifdef KR_headers | ||
597 | (a, b) Bigint *a, *b; | ||
598 | #else | ||
599 | (Bigint *a, Bigint *b) | ||
600 | #endif | ||
601 | { | 558 | { |
602 | Bigint *c; | 559 | Bigint *c; |
603 | int k, wa, wb, wc; | 560 | int k, wa, wb, wc; |
@@ -628,7 +585,7 @@ mult | |||
628 | xc0 = c->x; | 585 | xc0 = c->x; |
629 | #ifdef Pack_32 | 586 | #ifdef Pack_32 |
630 | for(; xb < xbe; xb++, xc0++) { | 587 | for(; xb < xbe; xb++, xc0++) { |
631 | if (y = *xb & 0xffff) { | 588 | if ((y = *xb & 0xffff)) { |
632 | x = xa; | 589 | x = xa; |
633 | xc = xc0; | 590 | xc = xc0; |
634 | carry = 0; | 591 | carry = 0; |
@@ -642,7 +599,7 @@ mult | |||
642 | while(x < xae); | 599 | while(x < xae); |
643 | *xc = carry; | 600 | *xc = carry; |
644 | } | 601 | } |
645 | if (y = *xb >> 16) { | 602 | if ((y = *xb >> 16)) { |
646 | x = xa; | 603 | x = xa; |
647 | xc = xc0; | 604 | xc = xc0; |
648 | carry = 0; | 605 | carry = 0; |
@@ -682,18 +639,13 @@ mult | |||
682 | static Bigint *p5s; | 639 | static Bigint *p5s; |
683 | 640 | ||
684 | static Bigint * | 641 | static Bigint * |
685 | pow5mult | 642 | pow5mult(Bigint *b, int k) |
686 | #ifdef KR_headers | ||
687 | (b, k) Bigint *b; int k; | ||
688 | #else | ||
689 | (Bigint *b, int k) | ||
690 | #endif | ||
691 | { | 643 | { |
692 | Bigint *b1, *p5, *p51; | 644 | Bigint *b1, *p5, *p51; |
693 | int i; | 645 | int i; |
694 | static int p05[3] = { 5, 25, 125 }; | 646 | static int p05[3] = { 5, 25, 125 }; |
695 | 647 | ||
696 | if (i = k & 3) | 648 | if ((i = k & 3)) |
697 | b = multadd(b, p05[i-1], 0); | 649 | b = multadd(b, p05[i-1], 0); |
698 | 650 | ||
699 | if (!(k >>= 2)) | 651 | if (!(k >>= 2)) |
@@ -721,12 +673,7 @@ pow5mult | |||
721 | } | 673 | } |
722 | 674 | ||
723 | static Bigint * | 675 | static Bigint * |
724 | lshift | 676 | lshift(Bigint *b, int k) |
725 | #ifdef KR_headers | ||
726 | (b, k) Bigint *b; int k; | ||
727 | #else | ||
728 | (Bigint *b, int k) | ||
729 | #endif | ||
730 | { | 677 | { |
731 | int i, k1, n, n1; | 678 | int i, k1, n, n1; |
732 | Bigint *b1; | 679 | Bigint *b1; |
@@ -756,7 +703,7 @@ lshift | |||
756 | z = *x++ >> k1; | 703 | z = *x++ >> k1; |
757 | } | 704 | } |
758 | while(x < xe); | 705 | while(x < xe); |
759 | if (*x1 = z) | 706 | if ((*x1 = z)) |
760 | ++n1; | 707 | ++n1; |
761 | } | 708 | } |
762 | #else | 709 | #else |
@@ -781,12 +728,7 @@ lshift | |||
781 | } | 728 | } |
782 | 729 | ||
783 | static int | 730 | static int |
784 | cmp | 731 | cmp(Bigint *a, Bigint *b) |
785 | #ifdef KR_headers | ||
786 | (a, b) Bigint *a, *b; | ||
787 | #else | ||
788 | (Bigint *a, Bigint *b) | ||
789 | #endif | ||
790 | { | 732 | { |
791 | ULong *xa, *xa0, *xb, *xb0; | 733 | ULong *xa, *xa0, *xb, *xb0; |
792 | int i, j; | 734 | int i, j; |
@@ -815,12 +757,7 @@ cmp | |||
815 | } | 757 | } |
816 | 758 | ||
817 | static Bigint * | 759 | static Bigint * |
818 | diff | 760 | diff(Bigint *a, Bigint *b) |
819 | #ifdef KR_headers | ||
820 | (a, b) Bigint *a, *b; | ||
821 | #else | ||
822 | (Bigint *a, Bigint *b) | ||
823 | #endif | ||
824 | { | 761 | { |
825 | Bigint *c; | 762 | Bigint *c; |
826 | int i, wa, wb; | 763 | int i, wa, wb; |
@@ -897,16 +834,13 @@ diff | |||
897 | } | 834 | } |
898 | 835 | ||
899 | static double | 836 | static double |
900 | ulp | 837 | ulp(double _x) |
901 | #ifdef KR_headers | ||
902 | (x) double x; | ||
903 | #else | ||
904 | (double x) | ||
905 | #endif | ||
906 | { | 838 | { |
907 | register Long L; | 839 | _double x; |
908 | double a; | 840 | Long L; |
841 | _double a; | ||
909 | 842 | ||
843 | value(x) = _x; | ||
910 | L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; | 844 | L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1; |
911 | #ifndef Sudden_Underflow | 845 | #ifndef Sudden_Underflow |
912 | if (L > 0) { | 846 | if (L > 0) { |
@@ -931,20 +865,15 @@ ulp | |||
931 | } | 865 | } |
932 | } | 866 | } |
933 | #endif | 867 | #endif |
934 | return a; | 868 | return value(a); |
935 | } | 869 | } |
936 | 870 | ||
937 | static double | 871 | static double |
938 | b2d | 872 | b2d(Bigint *a, int *e) |
939 | #ifdef KR_headers | ||
940 | (a, e) Bigint *a; int *e; | ||
941 | #else | ||
942 | (Bigint *a, int *e) | ||
943 | #endif | ||
944 | { | 873 | { |
945 | ULong *xa, *xa0, w, y, z; | 874 | ULong *xa, *xa0, w, y, z; |
946 | int k; | 875 | int k; |
947 | double d; | 876 | _double d; |
948 | #ifdef VAX | 877 | #ifdef VAX |
949 | ULong d0, d1; | 878 | ULong d0, d1; |
950 | #else | 879 | #else |
@@ -1001,22 +930,22 @@ b2d | |||
1001 | #undef d0 | 930 | #undef d0 |
1002 | #undef d1 | 931 | #undef d1 |
1003 | #endif | 932 | #endif |
1004 | return d; | 933 | return value(d); |
1005 | } | 934 | } |
1006 | 935 | ||
1007 | static Bigint * | 936 | static Bigint * |
1008 | d2b | 937 | d2b(double _d, int *e, int *bits) |
1009 | #ifdef KR_headers | ||
1010 | (d, e, bits) double d; int *e, *bits; | ||
1011 | #else | ||
1012 | (double d, int *e, int *bits) | ||
1013 | #endif | ||
1014 | { | 938 | { |
1015 | Bigint *b; | 939 | Bigint *b; |
1016 | int de, i, k; | 940 | int de, i, k; |
1017 | ULong *x, y, z; | 941 | ULong *x, y, z; |
942 | _double d; | ||
1018 | #ifdef VAX | 943 | #ifdef VAX |
1019 | ULong d0, d1; | 944 | ULong d0, d1; |
945 | #endif | ||
946 | |||
947 | value(d) = _d; | ||
948 | #ifdef VAX | ||
1020 | d0 = word0(d) >> 16 | word0(d) << 16; | 949 | d0 = word0(d) >> 16 | word0(d) << 16; |
1021 | d1 = word1(d) >> 16 | word1(d) << 16; | 950 | d1 = word1(d) >> 16 | word1(d) << 16; |
1022 | #else | 951 | #else |
@@ -1134,18 +1063,13 @@ d2b | |||
1134 | #undef d1 | 1063 | #undef d1 |
1135 | 1064 | ||
1136 | static double | 1065 | static double |
1137 | ratio | 1066 | ratio(Bigint *a, Bigint *b) |
1138 | #ifdef KR_headers | ||
1139 | (a, b) Bigint *a, *b; | ||
1140 | #else | ||
1141 | (Bigint *a, Bigint *b) | ||
1142 | #endif | ||
1143 | { | 1067 | { |
1144 | double da, db; | 1068 | _double da, db; |
1145 | int k, ka, kb; | 1069 | int k, ka, kb; |
1146 | 1070 | ||
1147 | da = b2d(a, &ka); | 1071 | value(da) = b2d(a, &ka); |
1148 | db = b2d(b, &kb); | 1072 | value(db) = b2d(b, &kb); |
1149 | #ifdef Pack_32 | 1073 | #ifdef Pack_32 |
1150 | k = ka - kb + 32*(a->wds - b->wds); | 1074 | k = ka - kb + 32*(a->wds - b->wds); |
1151 | #else | 1075 | #else |
@@ -1171,7 +1095,7 @@ ratio | |||
1171 | word0(db) += k*Exp_msk1; | 1095 | word0(db) += k*Exp_msk1; |
1172 | } | 1096 | } |
1173 | #endif | 1097 | #endif |
1174 | return da / db; | 1098 | return value(da) / value(db); |
1175 | } | 1099 | } |
1176 | 1100 | ||
1177 | static CONST double | 1101 | static CONST double |
@@ -1201,32 +1125,24 @@ static CONST double tinytens[] = { 1e-16, 1e-32 }; | |||
1201 | #endif | 1125 | #endif |
1202 | 1126 | ||
1203 | double | 1127 | double |
1204 | strtod | 1128 | strtod(CONST char *s00, char **se) |
1205 | #ifdef KR_headers | ||
1206 | (s00, se) CONST char *s00; char **se; | ||
1207 | #else | ||
1208 | (CONST char *s00, char **se) | ||
1209 | #endif | ||
1210 | { | 1129 | { |
1211 | int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, | 1130 | int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, |
1212 | e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; | 1131 | e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign; |
1213 | CONST char *s, *s0, *s1; | 1132 | CONST char *s, *s0, *s1; |
1214 | double aadj, aadj1, adj, rv, rv0; | 1133 | double aadj, aadj1, adj; |
1134 | _double rv, rv0; | ||
1215 | Long L; | 1135 | Long L; |
1216 | ULong y, z; | 1136 | ULong y, z; |
1217 | Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; | 1137 | Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; |
1218 | 1138 | ||
1219 | #ifndef KR_headers | ||
1220 | CONST char decimal_point = localeconv()->decimal_point[0]; | 1139 | CONST char decimal_point = localeconv()->decimal_point[0]; |
1221 | #else | ||
1222 | CONST char decimal_point = '.'; | ||
1223 | #endif | ||
1224 | 1140 | ||
1225 | sign = nz0 = nz = 0; | 1141 | sign = nz0 = nz = 0; |
1226 | rv = 0.; | 1142 | value(rv) = 0.; |
1227 | 1143 | ||
1228 | 1144 | ||
1229 | for(s = s00; isspace(*s); s++) | 1145 | for(s = s00; isspace((unsigned char) *s); s++) |
1230 | ; | 1146 | ; |
1231 | 1147 | ||
1232 | if (*s == '-') { | 1148 | if (*s == '-') { |
@@ -1340,9 +1256,9 @@ strtod | |||
1340 | if (!nd0) | 1256 | if (!nd0) |
1341 | nd0 = nd; | 1257 | nd0 = nd; |
1342 | k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; | 1258 | k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1; |
1343 | rv = y; | 1259 | value(rv) = y; |
1344 | if (k > 9) | 1260 | if (k > 9) |
1345 | rv = tens[k - 9] * rv + z; | 1261 | value(rv) = tens[k - 9] * value(rv) + z; |
1346 | bd0 = 0; | 1262 | bd0 = 0; |
1347 | if (nd <= DBL_DIG | 1263 | if (nd <= DBL_DIG |
1348 | #ifndef RND_PRODQUOT | 1264 | #ifndef RND_PRODQUOT |
@@ -1356,7 +1272,8 @@ strtod | |||
1356 | #ifdef VAX | 1272 | #ifdef VAX |
1357 | goto vax_ovfl_check; | 1273 | goto vax_ovfl_check; |
1358 | #else | 1274 | #else |
1359 | /* rv = */ rounded_product(rv, tens[e]); | 1275 | /* value(rv) = */ rounded_product(value(rv), |
1276 | tens[e]); | ||
1360 | goto ret; | 1277 | goto ret; |
1361 | #endif | 1278 | #endif |
1362 | } | 1279 | } |
@@ -1366,27 +1283,30 @@ strtod | |||
1366 | * this for larger i values. | 1283 | * this for larger i values. |
1367 | */ | 1284 | */ |
1368 | e -= i; | 1285 | e -= i; |
1369 | rv *= tens[i]; | 1286 | value(rv) *= tens[i]; |
1370 | #ifdef VAX | 1287 | #ifdef VAX |
1371 | /* VAX exponent range is so narrow we must | 1288 | /* VAX exponent range is so narrow we must |
1372 | * worry about overflow here... | 1289 | * worry about overflow here... |
1373 | */ | 1290 | */ |
1374 | vax_ovfl_check: | 1291 | vax_ovfl_check: |
1375 | word0(rv) -= P*Exp_msk1; | 1292 | word0(rv) -= P*Exp_msk1; |
1376 | /* rv = */ rounded_product(rv, tens[e]); | 1293 | /* value(rv) = */ rounded_product(value(rv), |
1294 | tens[e]); | ||
1377 | if ((word0(rv) & Exp_mask) | 1295 | if ((word0(rv) & Exp_mask) |
1378 | > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) | 1296 | > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) |
1379 | goto ovfl; | 1297 | goto ovfl; |
1380 | word0(rv) += P*Exp_msk1; | 1298 | word0(rv) += P*Exp_msk1; |
1381 | #else | 1299 | #else |
1382 | /* rv = */ rounded_product(rv, tens[e]); | 1300 | /* value(rv) = */ rounded_product(value(rv), |
1301 | tens[e]); | ||
1383 | #endif | 1302 | #endif |
1384 | goto ret; | 1303 | goto ret; |
1385 | } | 1304 | } |
1386 | } | 1305 | } |
1387 | #ifndef Inaccurate_Divide | 1306 | #ifndef Inaccurate_Divide |
1388 | else if (e >= -Ten_pmax) { | 1307 | else if (e >= -Ten_pmax) { |
1389 | /* rv = */ rounded_quotient(rv, tens[-e]); | 1308 | /* value(rv) = */ rounded_quotient(value(rv), |
1309 | tens[-e]); | ||
1390 | goto ret; | 1310 | goto ret; |
1391 | } | 1311 | } |
1392 | #endif | 1312 | #endif |
@@ -1397,13 +1317,13 @@ strtod | |||
1397 | 1317 | ||
1398 | if (e1 > 0) { | 1318 | if (e1 > 0) { |
1399 | if (i = e1 & 15) | 1319 | if (i = e1 & 15) |
1400 | rv *= tens[i]; | 1320 | value(rv) *= tens[i]; |
1401 | if (e1 &= ~15) { | 1321 | if (e1 &= ~15) { |
1402 | if (e1 > DBL_MAX_10_EXP) { | 1322 | if (e1 > DBL_MAX_10_EXP) { |
1403 | ovfl: | 1323 | ovfl: |
1404 | errno = ERANGE; | 1324 | errno = ERANGE; |
1405 | #ifdef __STDC__ | 1325 | #ifndef Bad_float_h |
1406 | rv = HUGE_VAL; | 1326 | value(rv) = HUGE_VAL; |
1407 | #else | 1327 | #else |
1408 | /* Can't trust HUGE_VAL */ | 1328 | /* Can't trust HUGE_VAL */ |
1409 | #ifdef IEEE_Arith | 1329 | #ifdef IEEE_Arith |
@@ -1421,10 +1341,10 @@ strtod | |||
1421 | if (e1 >>= 4) { | 1341 | if (e1 >>= 4) { |
1422 | for(j = 0; e1 > 1; j++, e1 >>= 1) | 1342 | for(j = 0; e1 > 1; j++, e1 >>= 1) |
1423 | if (e1 & 1) | 1343 | if (e1 & 1) |
1424 | rv *= bigtens[j]; | 1344 | value(rv) *= bigtens[j]; |
1425 | /* The last multiplication could overflow. */ | 1345 | /* The last multiplication could overflow. */ |
1426 | word0(rv) -= P*Exp_msk1; | 1346 | word0(rv) -= P*Exp_msk1; |
1427 | rv *= bigtens[j]; | 1347 | value(rv) *= bigtens[j]; |
1428 | if ((z = word0(rv) & Exp_mask) | 1348 | if ((z = word0(rv) & Exp_mask) |
1429 | > Exp_msk1*(DBL_MAX_EXP+Bias-P)) | 1349 | > Exp_msk1*(DBL_MAX_EXP+Bias-P)) |
1430 | goto ovfl; | 1350 | goto ovfl; |
@@ -1443,23 +1363,23 @@ strtod | |||
1443 | else if (e1 < 0) { | 1363 | else if (e1 < 0) { |
1444 | e1 = -e1; | 1364 | e1 = -e1; |
1445 | if (i = e1 & 15) | 1365 | if (i = e1 & 15) |
1446 | rv /= tens[i]; | 1366 | value(rv) /= tens[i]; |
1447 | if (e1 &= ~15) { | 1367 | if (e1 &= ~15) { |
1448 | e1 >>= 4; | 1368 | e1 >>= 4; |
1449 | if (e1 >= 1 << n_bigtens) | 1369 | if (e1 >= 1 << n_bigtens) |
1450 | goto undfl; | 1370 | goto undfl; |
1451 | for(j = 0; e1 > 1; j++, e1 >>= 1) | 1371 | for(j = 0; e1 > 1; j++, e1 >>= 1) |
1452 | if (e1 & 1) | 1372 | if (e1 & 1) |
1453 | rv *= tinytens[j]; | 1373 | value(rv) *= tinytens[j]; |
1454 | /* The last multiplication could underflow. */ | 1374 | /* The last multiplication could underflow. */ |
1455 | rv0 = rv; | 1375 | value(rv0) = value(rv); |
1456 | rv *= tinytens[j]; | 1376 | value(rv) *= tinytens[j]; |
1457 | if (!rv) { | 1377 | if (!value(rv)) { |
1458 | rv = 2.*rv0; | 1378 | value(rv) = 2.*value(rv0); |
1459 | rv *= tinytens[j]; | 1379 | value(rv) *= tinytens[j]; |
1460 | if (!rv) { | 1380 | if (!value(rv)) { |
1461 | undfl: | 1381 | undfl: |
1462 | rv = 0.; | 1382 | value(rv) = 0.; |
1463 | errno = ERANGE; | 1383 | errno = ERANGE; |
1464 | if (bd0) | 1384 | if (bd0) |
1465 | goto retfree; | 1385 | goto retfree; |
@@ -1483,7 +1403,7 @@ strtod | |||
1483 | for(;;) { | 1403 | for(;;) { |
1484 | bd = Balloc(bd0->k); | 1404 | bd = Balloc(bd0->k); |
1485 | Bcopy(bd, bd0); | 1405 | Bcopy(bd, bd0); |
1486 | bb = d2b(rv, &bbe, &bbbits); /* rv = bb * 2^bbe */ | 1406 | bb = d2b(value(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */ |
1487 | bs = i2b(1); | 1407 | bs = i2b(1); |
1488 | 1408 | ||
1489 | if (e >= 0) { | 1409 | if (e >= 0) { |
@@ -1595,12 +1515,12 @@ strtod | |||
1595 | break; | 1515 | break; |
1596 | #endif | 1516 | #endif |
1597 | if (dsign) | 1517 | if (dsign) |
1598 | rv += ulp(rv); | 1518 | value(rv) += ulp(value(rv)); |
1599 | #ifndef ROUND_BIASED | 1519 | #ifndef ROUND_BIASED |
1600 | else { | 1520 | else { |
1601 | rv -= ulp(rv); | 1521 | value(rv) -= ulp(value(rv)); |
1602 | #ifndef Sudden_Underflow | 1522 | #ifndef Sudden_Underflow |
1603 | if (!rv) | 1523 | if (!value(rv)) |
1604 | goto undfl; | 1524 | goto undfl; |
1605 | #endif | 1525 | #endif |
1606 | } | 1526 | } |
@@ -1651,10 +1571,10 @@ strtod | |||
1651 | /* Check for overflow */ | 1571 | /* Check for overflow */ |
1652 | 1572 | ||
1653 | if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { | 1573 | if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) { |
1654 | rv0 = rv; | 1574 | value(rv0) = value(rv); |
1655 | word0(rv) -= P*Exp_msk1; | 1575 | word0(rv) -= P*Exp_msk1; |
1656 | adj = aadj1 * ulp(rv); | 1576 | adj = aadj1 * ulp(value(rv)); |
1657 | rv += adj; | 1577 | value(rv) += adj; |
1658 | if ((word0(rv) & Exp_mask) >= | 1578 | if ((word0(rv) & Exp_mask) >= |
1659 | Exp_msk1*(DBL_MAX_EXP+Bias-P)) { | 1579 | Exp_msk1*(DBL_MAX_EXP+Bias-P)) { |
1660 | if (word0(rv0) == Big0 && word1(rv0) == Big1) | 1580 | if (word0(rv0) == Big0 && word1(rv0) == Big1) |
@@ -1669,10 +1589,10 @@ strtod | |||
1669 | else { | 1589 | else { |
1670 | #ifdef Sudden_Underflow | 1590 | #ifdef Sudden_Underflow |
1671 | if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { | 1591 | if ((word0(rv) & Exp_mask) <= P*Exp_msk1) { |
1672 | rv0 = rv; | 1592 | value(rv0) = value(rv); |
1673 | word0(rv) += P*Exp_msk1; | 1593 | word0(rv) += P*Exp_msk1; |
1674 | adj = aadj1 * ulp(rv); | 1594 | adj = aadj1 * ulp(value(rv)); |
1675 | rv += adj; | 1595 | value(rv) += adj; |
1676 | #ifdef IBM | 1596 | #ifdef IBM |
1677 | if ((word0(rv) & Exp_mask) < P*Exp_msk1) | 1597 | if ((word0(rv) & Exp_mask) < P*Exp_msk1) |
1678 | #else | 1598 | #else |
@@ -1690,8 +1610,8 @@ strtod | |||
1690 | word0(rv) -= P*Exp_msk1; | 1610 | word0(rv) -= P*Exp_msk1; |
1691 | } | 1611 | } |
1692 | else { | 1612 | else { |
1693 | adj = aadj1 * ulp(rv); | 1613 | adj = aadj1 * ulp(value(rv)); |
1694 | rv += adj; | 1614 | value(rv) += adj; |
1695 | } | 1615 | } |
1696 | #else | 1616 | #else |
1697 | /* Compute adj so that the IEEE rounding rules will | 1617 | /* Compute adj so that the IEEE rounding rules will |
@@ -1706,8 +1626,8 @@ strtod | |||
1706 | if (!dsign) | 1626 | if (!dsign) |
1707 | aadj1 = -aadj1; | 1627 | aadj1 = -aadj1; |
1708 | } | 1628 | } |
1709 | adj = aadj1 * ulp(rv); | 1629 | adj = aadj1 * ulp(value(rv)); |
1710 | rv += adj; | 1630 | value(rv) += adj; |
1711 | #endif | 1631 | #endif |
1712 | } | 1632 | } |
1713 | z = word0(rv) & Exp_mask; | 1633 | z = word0(rv) & Exp_mask; |
@@ -1738,16 +1658,11 @@ strtod | |||
1738 | ret: | 1658 | ret: |
1739 | if (se) | 1659 | if (se) |
1740 | *se = (char *)s; | 1660 | *se = (char *)s; |
1741 | return sign ? -rv : rv; | 1661 | return sign ? -value(rv) : value(rv); |
1742 | } | 1662 | } |
1743 | 1663 | ||
1744 | static int | 1664 | static int |
1745 | quorem | 1665 | quorem(Bigint *b, Bigint *S) |
1746 | #ifdef KR_headers | ||
1747 | (b, S) Bigint *b, *S; | ||
1748 | #else | ||
1749 | (Bigint *b, Bigint *S) | ||
1750 | #endif | ||
1751 | { | 1666 | { |
1752 | int n; | 1667 | int n; |
1753 | Long borrow, y; | 1668 | Long borrow, y; |
@@ -1882,13 +1797,7 @@ quorem | |||
1882 | */ | 1797 | */ |
1883 | 1798 | ||
1884 | char * | 1799 | char * |
1885 | __dtoa | 1800 | __dtoa(double _d, int mode, int ndigits, int *decpt, int *sign, char **rve) |
1886 | #ifdef KR_headers | ||
1887 | (d, mode, ndigits, decpt, sign, rve) | ||
1888 | double d; int mode, ndigits, *decpt, *sign; char **rve; | ||
1889 | #else | ||
1890 | (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) | ||
1891 | #endif | ||
1892 | { | 1801 | { |
1893 | /* Arguments ndigits, decpt, sign are similar to those | 1802 | /* Arguments ndigits, decpt, sign are similar to those |
1894 | of ecvt and fcvt; trailing zeros are suppressed from | 1803 | of ecvt and fcvt; trailing zeros are suppressed from |
@@ -1933,11 +1842,13 @@ __dtoa | |||
1933 | ULong x; | 1842 | ULong x; |
1934 | #endif | 1843 | #endif |
1935 | Bigint *b, *b1, *delta, *mlo, *mhi, *S; | 1844 | Bigint *b, *b1, *delta, *mlo, *mhi, *S; |
1936 | double d2, ds, eps; | 1845 | double ds; |
1937 | char *s, *s0; | 1846 | char *s, *s0; |
1938 | static Bigint *result; | 1847 | static Bigint *result; |
1939 | static int result_k; | 1848 | static int result_k; |
1849 | _double d, d2, eps; | ||
1940 | 1850 | ||
1851 | value(d) = _d; | ||
1941 | if (result) { | 1852 | if (result) { |
1942 | result->k = result_k; | 1853 | result->k = result_k; |
1943 | result->maxwds = 1 << result_k; | 1854 | result->maxwds = 1 << result_k; |
@@ -1964,7 +1875,7 @@ __dtoa | |||
1964 | *decpt = 9999; | 1875 | *decpt = 9999; |
1965 | s = | 1876 | s = |
1966 | #ifdef IEEE_Arith | 1877 | #ifdef IEEE_Arith |
1967 | !word1(d) && !(word0(d) & 0xfffff) ? "Infinity" : | 1878 | !word1(d) && !(word0(d) & 0xfffff) ? ndigits < 8 ? "Inf" : "Infinity" : |
1968 | #endif | 1879 | #endif |
1969 | "NaN"; | 1880 | "NaN"; |
1970 | if (rve) | 1881 | if (rve) |
@@ -1977,9 +1888,9 @@ __dtoa | |||
1977 | } | 1888 | } |
1978 | #endif | 1889 | #endif |
1979 | #ifdef IBM | 1890 | #ifdef IBM |
1980 | d += 0; /* normalize */ | 1891 | value(d) += 0; /* normalize */ |
1981 | #endif | 1892 | #endif |
1982 | if (!d) { | 1893 | if (!value(d)) { |
1983 | *decpt = 1; | 1894 | *decpt = 1; |
1984 | s = "0"; | 1895 | s = "0"; |
1985 | if (rve) | 1896 | if (rve) |
@@ -1987,18 +1898,18 @@ __dtoa | |||
1987 | return s; | 1898 | return s; |
1988 | } | 1899 | } |
1989 | 1900 | ||
1990 | b = d2b(d, &be, &bbits); | 1901 | b = d2b(value(d), &be, &bbits); |
1991 | #ifdef Sudden_Underflow | 1902 | #ifdef Sudden_Underflow |
1992 | i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); | 1903 | i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1)); |
1993 | #else | 1904 | #else |
1994 | if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { | 1905 | if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) { |
1995 | #endif | 1906 | #endif |
1996 | d2 = d; | 1907 | value(d2) = value(d); |
1997 | word0(d2) &= Frac_mask1; | 1908 | word0(d2) &= Frac_mask1; |
1998 | word0(d2) |= Exp_11; | 1909 | word0(d2) |= Exp_11; |
1999 | #ifdef IBM | 1910 | #ifdef IBM |
2000 | if (j = 11 - hi0bits(word0(d2) & Frac_mask)) | 1911 | if (j = 11 - hi0bits(word0(d2) & Frac_mask)) |
2001 | d2 /= 1 << j; | 1912 | value(d2) /= 1 << j; |
2002 | #endif | 1913 | #endif |
2003 | 1914 | ||
2004 | /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 | 1915 | /* log(x) ~=~ log(1.5) + (x-1.5)/1.5 |
@@ -2037,19 +1948,20 @@ __dtoa | |||
2037 | i = bbits + be + (Bias + (P-1) - 1); | 1948 | i = bbits + be + (Bias + (P-1) - 1); |
2038 | x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 | 1949 | x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32 |
2039 | : word1(d) << 32 - i; | 1950 | : word1(d) << 32 - i; |
2040 | d2 = x; | 1951 | value(d2) = x; |
2041 | word0(d2) -= 31*Exp_msk1; /* adjust exponent */ | 1952 | word0(d2) -= 31*Exp_msk1; /* adjust exponent */ |
2042 | i -= (Bias + (P-1) - 1) + 1; | 1953 | i -= (Bias + (P-1) - 1) + 1; |
2043 | denorm = 1; | 1954 | denorm = 1; |
2044 | } | 1955 | } |
2045 | #endif | 1956 | #endif |
2046 | ds = (d2-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981; | 1957 | ds = (value(d2)-1.5)*0.289529654602168 + 0.1760912590558 + |
1958 | i*0.301029995663981; | ||
2047 | k = (int)ds; | 1959 | k = (int)ds; |
2048 | if (ds < 0. && ds != k) | 1960 | if (ds < 0. && ds != k) |
2049 | k--; /* want k = floor(ds) */ | 1961 | k--; /* want k = floor(ds) */ |
2050 | k_check = 1; | 1962 | k_check = 1; |
2051 | if (k >= 0 && k <= Ten_pmax) { | 1963 | if (k >= 0 && k <= Ten_pmax) { |
2052 | if (d < tens[k]) | 1964 | if (value(d) < tens[k]) |
2053 | k--; | 1965 | k--; |
2054 | k_check = 0; | 1966 | k_check = 0; |
2055 | } | 1967 | } |
@@ -2116,7 +2028,7 @@ __dtoa | |||
2116 | /* Try to get by with floating-point arithmetic. */ | 2028 | /* Try to get by with floating-point arithmetic. */ |
2117 | 2029 | ||
2118 | i = 0; | 2030 | i = 0; |
2119 | d2 = d; | 2031 | value(d2) = value(d); |
2120 | k0 = k; | 2032 | k0 = k; |
2121 | ilim0 = ilim; | 2033 | ilim0 = ilim; |
2122 | ieps = 2; /* conservative */ | 2034 | ieps = 2; /* conservative */ |
@@ -2126,7 +2038,7 @@ __dtoa | |||
2126 | if (j & Bletch) { | 2038 | if (j & Bletch) { |
2127 | /* prevent overflows */ | 2039 | /* prevent overflows */ |
2128 | j &= Bletch - 1; | 2040 | j &= Bletch - 1; |
2129 | d /= bigtens[n_bigtens-1]; | 2041 | value(d) /= bigtens[n_bigtens-1]; |
2130 | ieps++; | 2042 | ieps++; |
2131 | } | 2043 | } |
2132 | for(; j; j >>= 1, i++) | 2044 | for(; j; j >>= 1, i++) |
@@ -2134,32 +2046,32 @@ __dtoa | |||
2134 | ieps++; | 2046 | ieps++; |
2135 | ds *= bigtens[i]; | 2047 | ds *= bigtens[i]; |
2136 | } | 2048 | } |
2137 | d /= ds; | 2049 | value(d) /= ds; |
2138 | } | 2050 | } |
2139 | else if (j1 = -k) { | 2051 | else if (j1 = -k) { |
2140 | d *= tens[j1 & 0xf]; | 2052 | value(d) *= tens[j1 & 0xf]; |
2141 | for(j = j1 >> 4; j; j >>= 1, i++) | 2053 | for(j = j1 >> 4; j; j >>= 1, i++) |
2142 | if (j & 1) { | 2054 | if (j & 1) { |
2143 | ieps++; | 2055 | ieps++; |
2144 | d *= bigtens[i]; | 2056 | value(d) *= bigtens[i]; |
2145 | } | 2057 | } |
2146 | } | 2058 | } |
2147 | if (k_check && d < 1. && ilim > 0) { | 2059 | if (k_check && value(d) < 1. && ilim > 0) { |
2148 | if (ilim1 <= 0) | 2060 | if (ilim1 <= 0) |
2149 | goto fast_failed; | 2061 | goto fast_failed; |
2150 | ilim = ilim1; | 2062 | ilim = ilim1; |
2151 | k--; | 2063 | k--; |
2152 | d *= 10.; | 2064 | value(d) *= 10.; |
2153 | ieps++; | 2065 | ieps++; |
2154 | } | 2066 | } |
2155 | eps = ieps*d + 7.; | 2067 | value(eps) = ieps*value(d) + 7.; |
2156 | word0(eps) -= (P-1)*Exp_msk1; | 2068 | word0(eps) -= (P-1)*Exp_msk1; |
2157 | if (ilim == 0) { | 2069 | if (ilim == 0) { |
2158 | S = mhi = 0; | 2070 | S = mhi = 0; |
2159 | d -= 5.; | 2071 | value(d) -= 5.; |
2160 | if (d > eps) | 2072 | if (value(d) > value(eps)) |
2161 | goto one_digit; | 2073 | goto one_digit; |
2162 | if (d < -eps) | 2074 | if (value(d) < -value(eps)) |
2163 | goto no_digits; | 2075 | goto no_digits; |
2164 | goto fast_failed; | 2076 | goto fast_failed; |
2165 | } | 2077 | } |
@@ -2168,33 +2080,33 @@ __dtoa | |||
2168 | /* Use Steele & White method of only | 2080 | /* Use Steele & White method of only |
2169 | * generating digits needed. | 2081 | * generating digits needed. |
2170 | */ | 2082 | */ |
2171 | eps = 0.5/tens[ilim-1] - eps; | 2083 | value(eps) = 0.5/tens[ilim-1] - value(eps); |
2172 | for(i = 0;;) { | 2084 | for(i = 0;;) { |
2173 | L = d; | 2085 | L = value(d); |
2174 | d -= L; | 2086 | value(d) -= L; |
2175 | *s++ = '0' + (int)L; | 2087 | *s++ = '0' + (int)L; |
2176 | if (d < eps) | 2088 | if (value(d) < value(eps)) |
2177 | goto ret1; | 2089 | goto ret1; |
2178 | if (1. - d < eps) | 2090 | if (1. - value(d) < value(eps)) |
2179 | goto bump_up; | 2091 | goto bump_up; |
2180 | if (++i >= ilim) | 2092 | if (++i >= ilim) |
2181 | break; | 2093 | break; |
2182 | eps *= 10.; | 2094 | value(eps) *= 10.; |
2183 | d *= 10.; | 2095 | value(d) *= 10.; |
2184 | } | 2096 | } |
2185 | } | 2097 | } |
2186 | else { | 2098 | else { |
2187 | #endif | 2099 | #endif |
2188 | /* Generate ilim digits, then fix them up. */ | 2100 | /* Generate ilim digits, then fix them up. */ |
2189 | eps *= tens[ilim-1]; | 2101 | value(eps) *= tens[ilim-1]; |
2190 | for(i = 1;; i++, d *= 10.) { | 2102 | for(i = 1;; i++, value(d) *= 10.) { |
2191 | L = d; | 2103 | L = value(d); |
2192 | d -= L; | 2104 | value(d) -= L; |
2193 | *s++ = '0' + (int)L; | 2105 | *s++ = '0' + (int)L; |
2194 | if (i == ilim) { | 2106 | if (i == ilim) { |
2195 | if (d > 0.5 + eps) | 2107 | if (value(d) > 0.5 + value(eps)) |
2196 | goto bump_up; | 2108 | goto bump_up; |
2197 | else if (d < 0.5 - eps) { | 2109 | else if (value(d) < 0.5 - value(eps)) { |
2198 | while(*--s == '0'); | 2110 | while(*--s == '0'); |
2199 | s++; | 2111 | s++; |
2200 | goto ret1; | 2112 | goto ret1; |
@@ -2207,7 +2119,7 @@ __dtoa | |||
2207 | #endif | 2119 | #endif |
2208 | fast_failed: | 2120 | fast_failed: |
2209 | s = s0; | 2121 | s = s0; |
2210 | d = d2; | 2122 | value(d) = value(d2); |
2211 | k = k0; | 2123 | k = k0; |
2212 | ilim = ilim0; | 2124 | ilim = ilim0; |
2213 | } | 2125 | } |
@@ -2219,24 +2131,24 @@ __dtoa | |||
2219 | ds = tens[k]; | 2131 | ds = tens[k]; |
2220 | if (ndigits < 0 && ilim <= 0) { | 2132 | if (ndigits < 0 && ilim <= 0) { |
2221 | S = mhi = 0; | 2133 | S = mhi = 0; |
2222 | if (ilim < 0 || d <= 5*ds) | 2134 | if (ilim < 0 || value(d) <= 5*ds) |
2223 | goto no_digits; | 2135 | goto no_digits; |
2224 | goto one_digit; | 2136 | goto one_digit; |
2225 | } | 2137 | } |
2226 | for(i = 1;; i++) { | 2138 | for(i = 1;; i++) { |
2227 | L = d / ds; | 2139 | L = value(d) / ds; |
2228 | d -= L*ds; | 2140 | value(d) -= L*ds; |
2229 | #ifdef Check_FLT_ROUNDS | 2141 | #ifdef Check_FLT_ROUNDS |
2230 | /* If FLT_ROUNDS == 2, L will usually be high by 1 */ | 2142 | /* If FLT_ROUNDS == 2, L will usually be high by 1 */ |
2231 | if (d < 0) { | 2143 | if (value(d) < 0) { |
2232 | L--; | 2144 | L--; |
2233 | d += ds; | 2145 | value(d) += ds; |
2234 | } | 2146 | } |
2235 | #endif | 2147 | #endif |
2236 | *s++ = '0' + (int)L; | 2148 | *s++ = '0' + (int)L; |
2237 | if (i == ilim) { | 2149 | if (i == ilim) { |
2238 | d += d; | 2150 | value(d) += value(d); |
2239 | if (d > ds || d == ds && L & 1) { | 2151 | if (value(d) > ds || value(d) == ds && L & 1) { |
2240 | bump_up: | 2152 | bump_up: |
2241 | while(*--s == '9') | 2153 | while(*--s == '9') |
2242 | if (s == s0) { | 2154 | if (s == s0) { |
@@ -2248,7 +2160,7 @@ __dtoa | |||
2248 | } | 2160 | } |
2249 | break; | 2161 | break; |
2250 | } | 2162 | } |
2251 | if (!(d *= 10.)) | 2163 | if (!(value(d) *= 10.)) |
2252 | break; | 2164 | break; |
2253 | } | 2165 | } |
2254 | goto ret1; | 2166 | goto ret1; |