ftoastr: port to hosts lacking strtof and strtold
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 19 Nov 2010 01:31:52 +0000 (17:31 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 19 Nov 2010 01:32:27 +0000 (17:32 -0800)
Problem reported by Bruno Haible in
<http://lists.gnu.org/archive/html/bug-gnulib/2010-11/msg00242.html>.
* lib/ftoastr.c (STRTOF): Define to strtod if in a pre-C99
environment and strtold (and presumably strtof) are not available.
* modules/ftoastr (Files): Add m4/c-strtod.m4.
(configure.ac): Require gl_C99_STRTOLD.

ChangeLog
lib/ftoastr.c
modules/ftoastr

index 7f0d117..a1043bd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2010-11-18  Paul Eggert  <eggert@cs.ucla.edu>
+
+       ftoastr: port to hosts lacking strtof and strtold
+       Problem reported by Bruno Haible in
+       <http://lists.gnu.org/archive/html/bug-gnulib/2010-11/msg00242.html>.
+       * lib/ftoastr.c (STRTOF): Define to strtod if in a pre-C99
+       environment and strtold (and presumably strtof) are not available.
+       * modules/ftoastr (Files): Add m4/c-strtod.m4.
+       (configure.ac): Require gl_C99_STRTOLD.
+
 2010-11-18  Bruno Haible  <bruno@clisp.org>
 
        c-strtold: Avoid link error on AIX 7.
index 25e0705..ddc5251 100644 (file)
 # define STRTOF strtof
 #endif
 
+/* On pre-C99 hosts, approximate strtof and strtold with strtod.  This
+   may generate one or two extra digits, but that's better than not
+   working at all.  Assume that strtof works if strtold does.  */
+#if LENGTH != 2 && ! HAVE_C99_STRTOLD
+# undef STRTOF
+# define STRTOF strtod
+#endif
+
 int
 FTOASTR (char *buf, size_t bufsize, int flags, int width, FLOAT x)
 {
index fbc0cba..64d0a77 100644 (file)
@@ -6,11 +6,13 @@ lib/ftoastr.h
 lib/ftoastr.c
 lib/dtoastr.c
 lib/ldtoastr.c
+m4/c-strtod.m4
 
 Depends-on:
 intprops
 
 configure.ac:
+AC_REQUIRE([gl_C99_STRTOLD])
 
 Makefile.am:
 lib_SOURCES += ftoastr.h ftoastr.c dtoastr.c ldtoastr.c