Commit fa2c4f56 authored by Paul Eggert's avatar Paul Eggert
Browse files

Use gnulib's ftoastr module.

parent 743c80a7
2011-01-09 Paul Eggert <>
Use gnulib ftoastr module.
* (GNULIB_MODULES): Add ftoastr. Remove dummy.
2011-01-08 Paul Eggert <>
......@@ -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.
--import --no-changelog --no-vc-files
sync-from-gnulib: $(gnulib_srcdir)
2011-01-09 Paul Eggert <>
Use gnulib's ftoastr module.
* print.c: Include ftoastr.h.
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 <>
Automate syncing from gnulib.
......@@ -50,36 +50,12 @@ Lisp_Object Vfloat_output_format, Qfloat_output_format;
#include <float.h>
#include <ftoastr.h>
/* Default to values appropriate for IEEE floating point. */
#ifndef FLT_RADIX
#define FLT_RADIX 2
#ifndef DBL_MANT_DIG
#define DBL_MANT_DIG 53
#ifndef DBL_DIG
#define DBL_DIG 15
#ifndef DBL_MIN
#define DBL_MIN 2.2250738585072014e-308
#undef DBL_MIN
/* 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 */
#define DOUBLE_DIGITS_BOUND ((int) ceil (log10 (pow (FLT_RADIX, DBL_MANT_DIG))))
/* 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;
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