Commit fa2c4f56 authored by Paul Eggert's avatar Paul Eggert

Use gnulib's ftoastr module.

parent 743c80a7
2011-01-09 Paul Eggert <eggert@cs.ucla.edu>
Use gnulib ftoastr module.
* Makefile.in (GNULIB_MODULES): Add ftoastr. Remove dummy.
2011-01-08 Paul Eggert <eggert@cs.ucla.edu>
Regenerate.
......
......@@ -330,7 +330,7 @@ $(gnulib_srcdir):
# Update modules from gnulib, for maintainers, who should have it in
# $(gnulib_srcdir) (relative to $(srcdir) and should have build tools
# as per $(gnulib_srcdir)/DEPENDENCIES.
GNULIB_MODULES = dummy # Just a dummy for now, to establish the mechanism.
GNULIB_MODULES = ftoastr
GNULIB_TOOL_FLAGS = \
--import --no-changelog --no-vc-files --makefile-name=gnulib.mk
sync-from-gnulib: $(gnulib_srcdir)
......
2011-01-09 Paul Eggert <eggert@cs.ucla.edu>
Use gnulib's ftoastr module.
* print.c: Include ftoastr.h.
(FLT_RADIX, DBL_MANT_DIG, DBL_DIG, DBL_MIN, DOUBLE_DIGITS_BOUND):
Remove; no longer needed.
(float_to_string): Use dtoastr rather than rolling our own code,
which had an off-by-one bug on non-IEEE hosts.
2011-01-08 Paul Eggert <eggert@cs.ucla.edu>
Automate syncing from gnulib.
......
......@@ -50,36 +50,12 @@ Lisp_Object Vfloat_output_format, Qfloat_output_format;
#if STDC_HEADERS
#include <float.h>
#endif
#include <ftoastr.h>
/* Default to values appropriate for IEEE floating point. */
#ifndef FLT_RADIX
#define FLT_RADIX 2
#endif
#ifndef DBL_MANT_DIG
#define DBL_MANT_DIG 53
#endif
#ifndef DBL_DIG
#define DBL_DIG 15
#endif
#ifndef DBL_MIN
#define DBL_MIN 2.2250738585072014e-308
#endif
#ifdef DBL_MIN_REPLACEMENT
#undef DBL_MIN
#define DBL_MIN DBL_MIN_REPLACEMENT
#endif
/* Define DOUBLE_DIGITS_BOUND, an upper bound on the number of decimal digits
needed to express a float without losing information.
The general-case formula is valid for the usual case, IEEE floating point,
but many compilers can't optimize the formula to an integer constant,
so make a special case for it. */
#if FLT_RADIX == 2 && DBL_MANT_DIG == 53
#define DOUBLE_DIGITS_BOUND 17 /* IEEE floating point */
#else
#define DOUBLE_DIGITS_BOUND ((int) ceil (log10 (pow (FLT_RADIX, DBL_MANT_DIG))))
#endif
/* Avoid actual stack overflow in print. */
int print_depth;
......@@ -1125,19 +1101,8 @@ float_to_string (unsigned char *buf, double data)
{
/* Generate the fewest number of digits that represent the
floating point value without losing information.
The following method is simple but a bit slow.
For ideas about speeding things up, please see:
Guy L Steele Jr & Jon L White, How to print floating-point numbers
accurately. SIGPLAN notices 25, 6 (June 1990), 112-126.
Robert G Burger & R Kent Dybvig, Printing floating point numbers
quickly and accurately, SIGPLAN notices 31, 5 (May 1996), 108-116. */
width = fabs (data) < DBL_MIN ? 1 : DBL_DIG;
do
sprintf (buf, "%.*g", width, data);
while (width++ < DOUBLE_DIGITS_BOUND && atof (buf) != data);
The 350 is by convention, e.g., this file's pigbuf. */
dtoastr (buf, 350, 0, 0, data);
}
else /* oink oink */
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment