diff options
author | das <das@FreeBSD.org> | 2003-03-12 20:30:00 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2003-03-12 20:30:00 +0000 |
commit | d02cfc3692917a1519b3251e739b4a04f056a232 (patch) | |
tree | 2227a906466b311329420d1e05832b3c4e9aef98 /lib/libc/stdio | |
parent | e89bff45972f418ac11fe0897158e917ac237bd0 (diff) | |
download | FreeBSD-src-d02cfc3692917a1519b3251e739b4a04f056a232.zip FreeBSD-src-d02cfc3692917a1519b3251e739b4a04f056a232.tar.gz |
Replace our ancient dtoa/strtod implementation with the gdtoa
package, a more recent, generalized set of routines. Among the
changes:
- Declare strtof() and strtold() in stdlib.h.
- Add glue to libc to support these routines for all kinds
of ``long double''.
- Update printf() to reflect the fact that dtoa works slightly
differently now.
As soon as I see that nothing has blown up, I will kill
src/lib/libc/stdlib/strtod.c. Soon printf() will be able
to use the new routines to output long doubles without loss
of precision, but numerous bugs in the existing code must
be addressed first.
Reviewed by: bde (briefly), mike (mentor), obrien
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/vfprintf.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index b0084c8..460d416 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -413,7 +413,10 @@ vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap) #define BUF ((MAXEXP*2)+MAXFRACT+1) /* + decimal point */ #define DEFPREC 6 -static char *cvt(double, int, int, char *, int *, int, int *, char **); +extern char *__dtoa(double, int, int, int *, int *, char **); +extern void __freedtoa(char *s); + +static char *cvt(double, int, int, char *, int *, int, int *); static int exponent(char *, int, int); #else /* no FLOATING_POINT */ @@ -840,11 +843,11 @@ fp_begin: if (prec == -1) } flags |= FPT; if (dtoaresult != NULL) { - free(dtoaresult); + __freedtoa(dtoaresult); dtoaresult = NULL; } - cp = cvt(_double, prec, flags, &softsign, - &expt, ch, &ndig, &dtoaresult); + dtoaresult = cp = cvt(_double, prec, flags, &softsign, + &expt, ch, &ndig); if (ch == 'g' || ch == 'G') { if (expt <= -4 || expt > prec) ch = (ch == 'g') ? 'e' : 'E'; @@ -1138,7 +1141,7 @@ done: error: #ifdef FLOATING_POINT if (dtoaresult != NULL) - free(dtoaresult); + __freedtoa(dtoaresult); #endif if (convbuf != NULL) free(convbuf); @@ -1508,11 +1511,9 @@ __grow_type_table (int nextarg, enum typeid **typetable, int *tablesize) #ifdef FLOATING_POINT -extern char *__dtoa(double, int, int, int *, int *, char **, char **); - static char * cvt(double value, int ndigits, int flags, char *sign, int *decpt, - int ch, int *length, char **dtoaresultp) + int ch, int *length) { int mode, dsgn; char *digits, *bp, *rve; @@ -1529,7 +1530,7 @@ cvt(double value, int ndigits, int flags, char *sign, int *decpt, ndigits++; mode = 2; /* ndigits significant digits */ } - digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve, dtoaresultp); + digits = __dtoa(value, mode, ndigits, decpt, &dsgn, &rve); *sign = dsgn != 0; if ((ch != 'g' && ch != 'G') || flags & ALT) { /* print trailing zeros */ |