diff options
author | pat <> | 2005-03-30 18:51:49 +0000 |
---|---|---|
committer | pat <> | 2005-03-30 18:51:49 +0000 |
commit | 894b6ab0099e7d9ca2ad9acb75246cd0a4542167 (patch) | |
tree | f9fb8e9324f6cbdc10d72cab8b889d470252465a /src/lib/libc/stdlib/strtod.c | |
parent | 162f8b042bf31ab94714a6f194e9836c08c085f5 (diff) | |
download | openbsd-894b6ab0099e7d9ca2ad9acb75246cd0a4542167.tar.gz openbsd-894b6ab0099e7d9ca2ad9acb75246cd0a4542167.tar.bz2 openbsd-894b6ab0099e7d9ca2ad9acb75246cd0a4542167.zip |
ansi + de-register
ok otto deraadt
Diffstat (limited to 'src/lib/libc/stdlib/strtod.c')
-rw-r--r-- | src/lib/libc/stdlib/strtod.c | 166 |
1 files changed, 24 insertions, 142 deletions
diff --git a/src/lib/libc/stdlib/strtod.c b/src/lib/libc/stdlib/strtod.c index 8e839d6155..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,7 +89,7 @@ | |||
90 | */ | 89 | */ |
91 | 90 | ||
92 | #if defined(LIBC_SCCS) && !defined(lint) | 91 | #if defined(LIBC_SCCS) && !defined(lint) |
93 | static char *rcsid = "$OpenBSD: strtod.c,v 1.19 2004/02/03 16:52:11 drahn 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__) || \ |
@@ -130,22 +129,13 @@ static char *rcsid = "$OpenBSD: strtod.c,v 1.19 2004/02/03 16:52:11 drahn Exp $" | |||
130 | #include "malloc.h" | 129 | #include "malloc.h" |
131 | #include "memory.h" | 130 | #include "memory.h" |
132 | #else | 131 | #else |
133 | #ifndef KR_headers | ||
134 | #include "stdlib.h" | 132 | #include "stdlib.h" |
135 | #include "string.h" | 133 | #include "string.h" |
136 | #include "locale.h" | 134 | #include "locale.h" |
137 | #else | ||
138 | #include "malloc.h" | ||
139 | #include "memory.h" | ||
140 | #endif | ||
141 | #endif | 135 | #endif |
142 | 136 | ||
143 | #ifdef MALLOC | 137 | #ifdef MALLOC |
144 | #ifdef KR_headers | ||
145 | extern char *MALLOC(); | ||
146 | #else | ||
147 | extern void *MALLOC(size_t); | 138 | extern void *MALLOC(size_t); |
148 | #endif | ||
149 | #else | 139 | #else |
150 | #define MALLOC malloc | 140 | #define MALLOC malloc |
151 | #endif | 141 | #endif |
@@ -203,12 +193,8 @@ extern "C" { | |||
203 | #endif | 193 | #endif |
204 | 194 | ||
205 | #ifndef CONST | 195 | #ifndef CONST |
206 | #ifdef KR_headers | ||
207 | #define CONST /* blank */ | ||
208 | #else | ||
209 | #define CONST const | 196 | #define CONST const |
210 | #endif | 197 | #endif |
211 | #endif | ||
212 | 198 | ||
213 | #ifdef Unsigned_Shifts | 199 | #ifdef Unsigned_Shifts |
214 | #define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; | 200 | #define Sign_Extend(a,b) if (b < 0) a |= 0xffff0000; |
@@ -341,11 +327,7 @@ typedef union { | |||
341 | #ifdef RND_PRODQUOT | 327 | #ifdef RND_PRODQUOT |
342 | #define rounded_product(a,b) a = rnd_prod(a, b) | 328 | #define rounded_product(a,b) a = rnd_prod(a, b) |
343 | #define rounded_quotient(a,b) a = rnd_quot(a, b) | 329 | #define rounded_quotient(a,b) a = rnd_quot(a, b) |
344 | #ifdef KR_headers | ||
345 | extern double rnd_prod(), rnd_quot(); | ||
346 | #else | ||
347 | extern double rnd_prod(double, double), rnd_quot(double, double); | 330 | extern double rnd_prod(double, double), rnd_quot(double, double); |
348 | #endif | ||
349 | #else | 331 | #else |
350 | #define rounded_product(a,b) a *= b | 332 | #define rounded_product(a,b) a *= b |
351 | #define rounded_quotient(a,b) a /= b | 333 | #define rounded_quotient(a,b) a /= b |
@@ -385,12 +367,7 @@ Bigint { | |||
385 | static Bigint *freelist[Kmax+1]; | 367 | static Bigint *freelist[Kmax+1]; |
386 | 368 | ||
387 | static Bigint * | 369 | static Bigint * |
388 | Balloc | 370 | Balloc(int k) |
389 | #ifdef KR_headers | ||
390 | (k) int k; | ||
391 | #else | ||
392 | (int k) | ||
393 | #endif | ||
394 | { | 371 | { |
395 | int x; | 372 | int x; |
396 | Bigint *rv; | 373 | Bigint *rv; |
@@ -409,12 +386,7 @@ Balloc | |||
409 | } | 386 | } |
410 | 387 | ||
411 | static void | 388 | static void |
412 | Bfree | 389 | Bfree(Bigint *v) |
413 | #ifdef KR_headers | ||
414 | (v) Bigint *v; | ||
415 | #else | ||
416 | (Bigint *v) | ||
417 | #endif | ||
418 | { | 390 | { |
419 | if (v) { | 391 | if (v) { |
420 | v->next = freelist[v->k]; | 392 | v->next = freelist[v->k]; |
@@ -426,12 +398,7 @@ Bfree | |||
426 | y->wds*sizeof(Long) + 2*sizeof(int)) | 398 | y->wds*sizeof(Long) + 2*sizeof(int)) |
427 | 399 | ||
428 | static Bigint * | 400 | static Bigint * |
429 | multadd | 401 | multadd(Bigint *b, int m, int a) /* multiply by m and add a */ |
430 | #ifdef KR_headers | ||
431 | (b, m, a) Bigint *b; int m, a; | ||
432 | #else | ||
433 | (Bigint *b, int m, int a) /* multiply by m and add a */ | ||
434 | #endif | ||
435 | { | 402 | { |
436 | int i, wds; | 403 | int i, wds; |
437 | ULong *x, y; | 404 | ULong *x, y; |
@@ -471,12 +438,7 @@ multadd | |||
471 | } | 438 | } |
472 | 439 | ||
473 | static Bigint * | 440 | static Bigint * |
474 | s2b | 441 | s2b(CONST char *s, int nd0, int nd, ULong y9) |
475 | #ifdef KR_headers | ||
476 | (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9; | ||
477 | #else | ||
478 | (CONST char *s, int nd0, int nd, ULong y9) | ||
479 | #endif | ||
480 | { | 442 | { |
481 | Bigint *b; | 443 | Bigint *b; |
482 | int i, k; | 444 | int i, k; |
@@ -509,14 +471,9 @@ s2b | |||
509 | } | 471 | } |
510 | 472 | ||
511 | static int | 473 | static int |
512 | hi0bits | 474 | hi0bits(ULong x) |
513 | #ifdef KR_headers | ||
514 | (x) register ULong x; | ||
515 | #else | ||
516 | (register ULong x) | ||
517 | #endif | ||
518 | { | 475 | { |
519 | register int k = 0; | 476 | int k = 0; |
520 | 477 | ||
521 | if (!(x & 0xffff0000)) { | 478 | if (!(x & 0xffff0000)) { |
522 | k = 16; | 479 | k = 16; |
@@ -543,15 +500,10 @@ hi0bits | |||
543 | } | 500 | } |
544 | 501 | ||
545 | static int | 502 | static int |
546 | lo0bits | 503 | lo0bits(ULong *y) |
547 | #ifdef KR_headers | ||
548 | (y) ULong *y; | ||
549 | #else | ||
550 | (ULong *y) | ||
551 | #endif | ||
552 | { | 504 | { |
553 | register int k; | 505 | int k; |
554 | register ULong x = *y; | 506 | ULong x = *y; |
555 | 507 | ||
556 | if (x & 7) { | 508 | if (x & 7) { |
557 | if (x & 1) | 509 | if (x & 1) |
@@ -591,12 +543,7 @@ lo0bits | |||
591 | } | 543 | } |
592 | 544 | ||
593 | static Bigint * | 545 | static Bigint * |
594 | i2b | 546 | i2b(int i) |
595 | #ifdef KR_headers | ||
596 | (i) int i; | ||
597 | #else | ||
598 | (int i) | ||
599 | #endif | ||
600 | { | 547 | { |
601 | Bigint *b; | 548 | Bigint *b; |
602 | 549 | ||
@@ -607,12 +554,7 @@ i2b | |||
607 | } | 554 | } |
608 | 555 | ||
609 | static Bigint * | 556 | static Bigint * |
610 | mult | 557 | mult(Bigint *a, Bigint *b) |
611 | #ifdef KR_headers | ||
612 | (a, b) Bigint *a, *b; | ||
613 | #else | ||
614 | (Bigint *a, Bigint *b) | ||
615 | #endif | ||
616 | { | 558 | { |
617 | Bigint *c; | 559 | Bigint *c; |
618 | int k, wa, wb, wc; | 560 | int k, wa, wb, wc; |
@@ -697,12 +639,7 @@ mult | |||
697 | static Bigint *p5s; | 639 | static Bigint *p5s; |
698 | 640 | ||
699 | static Bigint * | 641 | static Bigint * |
700 | pow5mult | 642 | pow5mult(Bigint *b, int k) |
701 | #ifdef KR_headers | ||
702 | (b, k) Bigint *b; int k; | ||
703 | #else | ||
704 | (Bigint *b, int k) | ||
705 | #endif | ||
706 | { | 643 | { |
707 | Bigint *b1, *p5, *p51; | 644 | Bigint *b1, *p5, *p51; |
708 | int i; | 645 | int i; |
@@ -736,12 +673,7 @@ pow5mult | |||
736 | } | 673 | } |
737 | 674 | ||
738 | static Bigint * | 675 | static Bigint * |
739 | lshift | 676 | lshift(Bigint *b, int k) |
740 | #ifdef KR_headers | ||
741 | (b, k) Bigint *b; int k; | ||
742 | #else | ||
743 | (Bigint *b, int k) | ||
744 | #endif | ||
745 | { | 677 | { |
746 | int i, k1, n, n1; | 678 | int i, k1, n, n1; |
747 | Bigint *b1; | 679 | Bigint *b1; |
@@ -796,12 +728,7 @@ lshift | |||
796 | } | 728 | } |
797 | 729 | ||
798 | static int | 730 | static int |
799 | cmp | 731 | cmp(Bigint *a, Bigint *b) |
800 | #ifdef KR_headers | ||
801 | (a, b) Bigint *a, *b; | ||
802 | #else | ||
803 | (Bigint *a, Bigint *b) | ||
804 | #endif | ||
805 | { | 732 | { |
806 | ULong *xa, *xa0, *xb, *xb0; | 733 | ULong *xa, *xa0, *xb, *xb0; |
807 | int i, j; | 734 | int i, j; |
@@ -830,12 +757,7 @@ cmp | |||
830 | } | 757 | } |
831 | 758 | ||
832 | static Bigint * | 759 | static Bigint * |
833 | diff | 760 | diff(Bigint *a, Bigint *b) |
834 | #ifdef KR_headers | ||
835 | (a, b) Bigint *a, *b; | ||
836 | #else | ||
837 | (Bigint *a, Bigint *b) | ||
838 | #endif | ||
839 | { | 761 | { |
840 | Bigint *c; | 762 | Bigint *c; |
841 | int i, wa, wb; | 763 | int i, wa, wb; |
@@ -912,15 +834,10 @@ diff | |||
912 | } | 834 | } |
913 | 835 | ||
914 | static double | 836 | static double |
915 | ulp | 837 | ulp(double _x) |
916 | #ifdef KR_headers | ||
917 | (_x) double _x; | ||
918 | #else | ||
919 | (double _x) | ||
920 | #endif | ||
921 | { | 838 | { |
922 | _double x; | 839 | _double x; |
923 | register Long L; | 840 | Long L; |
924 | _double a; | 841 | _double a; |
925 | 842 | ||
926 | value(x) = _x; | 843 | value(x) = _x; |
@@ -952,12 +869,7 @@ ulp | |||
952 | } | 869 | } |
953 | 870 | ||
954 | static double | 871 | static double |
955 | b2d | 872 | b2d(Bigint *a, int *e) |
956 | #ifdef KR_headers | ||
957 | (a, e) Bigint *a; int *e; | ||
958 | #else | ||
959 | (Bigint *a, int *e) | ||
960 | #endif | ||
961 | { | 873 | { |
962 | ULong *xa, *xa0, w, y, z; | 874 | ULong *xa, *xa0, w, y, z; |
963 | int k; | 875 | int k; |
@@ -1022,12 +934,7 @@ b2d | |||
1022 | } | 934 | } |
1023 | 935 | ||
1024 | static Bigint * | 936 | static Bigint * |
1025 | d2b | 937 | d2b(double _d, int *e, int *bits) |
1026 | #ifdef KR_headers | ||
1027 | (_d, e, bits) double d; int *e, *bits; | ||
1028 | #else | ||
1029 | (double _d, int *e, int *bits) | ||
1030 | #endif | ||
1031 | { | 938 | { |
1032 | Bigint *b; | 939 | Bigint *b; |
1033 | int de, i, k; | 940 | int de, i, k; |
@@ -1156,12 +1063,7 @@ d2b | |||
1156 | #undef d1 | 1063 | #undef d1 |
1157 | 1064 | ||
1158 | static double | 1065 | static double |
1159 | ratio | 1066 | ratio(Bigint *a, Bigint *b) |
1160 | #ifdef KR_headers | ||
1161 | (a, b) Bigint *a, *b; | ||
1162 | #else | ||
1163 | (Bigint *a, Bigint *b) | ||
1164 | #endif | ||
1165 | { | 1067 | { |
1166 | _double da, db; | 1068 | _double da, db; |
1167 | int k, ka, kb; | 1069 | int k, ka, kb; |
@@ -1223,12 +1125,7 @@ static CONST double tinytens[] = { 1e-16, 1e-32 }; | |||
1223 | #endif | 1125 | #endif |
1224 | 1126 | ||
1225 | double | 1127 | double |
1226 | strtod | 1128 | strtod(CONST char *s00, char **se) |
1227 | #ifdef KR_headers | ||
1228 | (s00, se) CONST char *s00; char **se; | ||
1229 | #else | ||
1230 | (CONST char *s00, char **se) | ||
1231 | #endif | ||
1232 | { | 1129 | { |
1233 | int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, | 1130 | int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign, |
1234 | 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; |
@@ -1239,11 +1136,7 @@ strtod | |||
1239 | ULong y, z; | 1136 | ULong y, z; |
1240 | Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; | 1137 | Bigint *bb, *bb1, *bd, *bd0, *bs, *delta; |
1241 | 1138 | ||
1242 | #ifndef KR_headers | ||
1243 | CONST char decimal_point = localeconv()->decimal_point[0]; | 1139 | CONST char decimal_point = localeconv()->decimal_point[0]; |
1244 | #else | ||
1245 | CONST char decimal_point = '.'; | ||
1246 | #endif | ||
1247 | 1140 | ||
1248 | sign = nz0 = nz = 0; | 1141 | sign = nz0 = nz = 0; |
1249 | value(rv) = 0.; | 1142 | value(rv) = 0.; |
@@ -1769,12 +1662,7 @@ strtod | |||
1769 | } | 1662 | } |
1770 | 1663 | ||
1771 | static int | 1664 | static int |
1772 | quorem | 1665 | quorem(Bigint *b, Bigint *S) |
1773 | #ifdef KR_headers | ||
1774 | (b, S) Bigint *b, *S; | ||
1775 | #else | ||
1776 | (Bigint *b, Bigint *S) | ||
1777 | #endif | ||
1778 | { | 1666 | { |
1779 | int n; | 1667 | int n; |
1780 | Long borrow, y; | 1668 | Long borrow, y; |
@@ -1909,13 +1797,7 @@ quorem | |||
1909 | */ | 1797 | */ |
1910 | 1798 | ||
1911 | char * | 1799 | char * |
1912 | __dtoa | 1800 | __dtoa(double _d, int mode, int ndigits, int *decpt, int *sign, char **rve) |
1913 | #ifdef KR_headers | ||
1914 | (_d, mode, ndigits, decpt, sign, rve) | ||
1915 | double _d; int mode, ndigits, *decpt, *sign; char **rve; | ||
1916 | #else | ||
1917 | (double _d, int mode, int ndigits, int *decpt, int *sign, char **rve) | ||
1918 | #endif | ||
1919 | { | 1801 | { |
1920 | /* Arguments ndigits, decpt, sign are similar to those | 1802 | /* Arguments ndigits, decpt, sign are similar to those |
1921 | of ecvt and fcvt; trailing zeros are suppressed from | 1803 | of ecvt and fcvt; trailing zeros are suppressed from |