aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-01-08 17:18:39 -0800
committerPaul Eggert2011-01-08 17:18:39 -0800
commitfa2c4f5619481856c8cdf33be987d5785f51b750 (patch)
tree70cdbb77315aaccccd98822732fb718d63d4855c /src
parent743c80a7253985de327fa6b3dc9ff1724da5cc78 (diff)
downloademacs-fa2c4f5619481856c8cdf33be987d5785f51b750.tar.gz
emacs-fa2c4f5619481856c8cdf33be987d5785f51b750.zip
Use gnulib's ftoastr module.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog9
-rw-r--r--src/print.c41
2 files changed, 12 insertions, 38 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index c8bcd2ab669..a7d7b87a9b5 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,12 @@
12011-01-09 Paul Eggert <eggert@cs.ucla.edu>
2
3 Use gnulib's ftoastr module.
4 * print.c: Include ftoastr.h.
5 (FLT_RADIX, DBL_MANT_DIG, DBL_DIG, DBL_MIN, DOUBLE_DIGITS_BOUND):
6 Remove; no longer needed.
7 (float_to_string): Use dtoastr rather than rolling our own code,
8 which had an off-by-one bug on non-IEEE hosts.
9
12011-01-08 Paul Eggert <eggert@cs.ucla.edu> 102011-01-08 Paul Eggert <eggert@cs.ucla.edu>
2 11
3 Automate syncing from gnulib. 12 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;
50#if STDC_HEADERS 50#if STDC_HEADERS
51#include <float.h> 51#include <float.h>
52#endif 52#endif
53#include <ftoastr.h>
53 54
54/* Default to values appropriate for IEEE floating point. */ 55/* Default to values appropriate for IEEE floating point. */
55#ifndef FLT_RADIX
56#define FLT_RADIX 2
57#endif
58#ifndef DBL_MANT_DIG
59#define DBL_MANT_DIG 53
60#endif
61#ifndef DBL_DIG 56#ifndef DBL_DIG
62#define DBL_DIG 15 57#define DBL_DIG 15
63#endif 58#endif
64#ifndef DBL_MIN
65#define DBL_MIN 2.2250738585072014e-308
66#endif
67
68#ifdef DBL_MIN_REPLACEMENT
69#undef DBL_MIN
70#define DBL_MIN DBL_MIN_REPLACEMENT
71#endif
72
73/* Define DOUBLE_DIGITS_BOUND, an upper bound on the number of decimal digits
74 needed to express a float without losing information.
75 The general-case formula is valid for the usual case, IEEE floating point,
76 but many compilers can't optimize the formula to an integer constant,
77 so make a special case for it. */
78#if FLT_RADIX == 2 && DBL_MANT_DIG == 53
79#define DOUBLE_DIGITS_BOUND 17 /* IEEE floating point */
80#else
81#define DOUBLE_DIGITS_BOUND ((int) ceil (log10 (pow (FLT_RADIX, DBL_MANT_DIG))))
82#endif
83 59
84/* Avoid actual stack overflow in print. */ 60/* Avoid actual stack overflow in print. */
85int print_depth; 61int print_depth;
@@ -1125,19 +1101,8 @@ float_to_string (unsigned char *buf, double data)
1125 { 1101 {
1126 /* Generate the fewest number of digits that represent the 1102 /* Generate the fewest number of digits that represent the
1127 floating point value without losing information. 1103 floating point value without losing information.
1128 The following method is simple but a bit slow. 1104 The 350 is by convention, e.g., this file's pigbuf. */
1129 For ideas about speeding things up, please see: 1105 dtoastr (buf, 350, 0, 0, data);
1130
1131 Guy L Steele Jr & Jon L White, How to print floating-point numbers
1132 accurately. SIGPLAN notices 25, 6 (June 1990), 112-126.
1133
1134 Robert G Burger & R Kent Dybvig, Printing floating point numbers
1135 quickly and accurately, SIGPLAN notices 31, 5 (May 1996), 108-116. */
1136
1137 width = fabs (data) < DBL_MIN ? 1 : DBL_DIG;
1138 do
1139 sprintf (buf, "%.*g", width, data);
1140 while (width++ < DOUBLE_DIGITS_BOUND && atof (buf) != data);
1141 } 1106 }
1142 else /* oink oink */ 1107 else /* oink oink */
1143 { 1108 {