changeset 112304:9539682ee916

Use gnulib's ftoastr module.
author Paul Eggert <eggert@cs.ucla.edu>
date Sat, 08 Jan 2011 17:18:39 -0800
parents 16ae11ee4ab8
children f31011c088d9
files ChangeLog Makefile.in src/ChangeLog src/print.c
diffstat 4 files changed, 18 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jan 08 13:19:44 2011 -0800
+++ b/ChangeLog	Sat Jan 08 17:18:39 2011 -0800
@@ -1,3 +1,8 @@
+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.
--- a/Makefile.in	Sat Jan 08 13:19:44 2011 -0800
+++ b/Makefile.in	Sat Jan 08 17:18:39 2011 -0800
@@ -330,7 +330,7 @@
 # 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)
--- a/src/ChangeLog	Sat Jan 08 13:19:44 2011 -0800
+++ b/src/ChangeLog	Sat Jan 08 17:18:39 2011 -0800
@@ -1,3 +1,12 @@
+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.
--- a/src/print.c	Sat Jan 08 13:19:44 2011 -0800
+++ b/src/print.c	Sat Jan 08 17:18:39 2011 -0800
@@ -50,36 +50,12 @@
 #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 @@
     {
       /* 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 */
     {