From: Paul Eggert Date: Sun, 9 Jan 2011 01:18:39 +0000 (-0800) Subject: Use gnulib's ftoastr module. X-Git-Tag: emacs-pretest-24.0.90~104^2~618^2~1322^2~256 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fa2c4f5619481856c8cdf33be987d5785f51b750;p=emacs.git Use gnulib's ftoastr module. --- diff --git a/ChangeLog b/ChangeLog index bff88249a55..2cb57b73075 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-01-09 Paul Eggert + + Use gnulib ftoastr module. + * Makefile.in (GNULIB_MODULES): Add ftoastr. Remove dummy. + 2011-01-08 Paul Eggert Regenerate. diff --git a/Makefile.in b/Makefile.in index dbe98f37fa1..30692b46a70 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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) diff --git a/src/ChangeLog b/src/ChangeLog index c8bcd2ab669..a7d7b87a9b5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2011-01-09 Paul Eggert + + 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 Automate syncing from gnulib. diff --git a/src/print.c b/src/print.c index 487fe91e475..993b17b668d 100644 --- a/src/print.c +++ b/src/print.c @@ -50,36 +50,12 @@ Lisp_Object Vfloat_output_format, Qfloat_output_format; #if STDC_HEADERS #include #endif +#include /* 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 */ {