2 dnl Copyright (C) 2002-2003, 2006-2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_STRTOD],
9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10 dnl Test whether strtod is declared.
11 dnl Don't call AC_FUNC_STRTOD, because it does not have the right guess
12 dnl when cross-compiling.
13 dnl Don't call AC_CHECK_FUNCS([strtod]) because it would collide with the
14 dnl ac_cv_func_strtod variable set by the AC_FUNC_STRTOD macro.
15 AC_CHECK_DECLS_ONCE([strtod])
16 if test $ac_cv_have_decl_strtod != yes; then
19 AC_CACHE_CHECK([whether strtod obeys C99], [gl_cv_func_strtod_works],
20 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
24 /* Compare two numbers with ==.
25 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
28 numeric_equal (double x, double y)
34 /* In some old versions of Linux (2000 or before), strtod mis-parses
35 strings with leading '+'. */
36 const char *string = " +69";
38 double value = strtod (string, &term);
39 if (value != 69 || term != (string + 4))
43 /* Under Solaris 2.4, strtod returns the wrong value for the
44 terminating character under some conditions. */
45 const char *string = "NaN";
47 strtod (string, &term);
48 if (term != string && *(term - 1) == 0)
52 /* Older glibc and Cygwin mis-parse "-0x". */
53 const char *string = "-0x";
55 double value = strtod (string, &term);
57 if (1.0 / value != -1.0 / zero || term != (string + 2))
61 /* Many platforms do not parse hex floats. */
62 const char *string = "0XaP+1";
64 double value = strtod (string, &term);
65 if (value != 20.0 || term != (string + 6))
69 /* Many platforms do not parse infinities. HP-UX 11.31 parses inf,
70 but mistakenly sets errno. */
71 const char *string = "inf";
75 value = strtod (string, &term);
76 if (value != HUGE_VAL || term != (string + 3) || errno)
80 /* glibc 2.7 and cygwin 1.5.24 misparse "nan()". */
81 const char *string = "nan()";
83 double value = strtod (string, &term);
84 if (numeric_equal (value, value) || term != (string + 5))
88 /* darwin 10.6.1 misparses "nan(". */
89 const char *string = "nan(";
91 double value = strtod (string, &term);
92 if (numeric_equal (value, value) || term != (string + 3))
96 [gl_cv_func_strtod_works=yes],
97 [gl_cv_func_strtod_works=no],
98 [dnl The last known bugs in glibc strtod(), as of this writing,
99 dnl were fixed in version 2.8
100 AC_EGREP_CPP([Lucky user],
102 #include <features.h>
103 #ifdef __GNU_LIBRARY__
104 #if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) || (__GLIBC__ > 2)
109 [gl_cv_func_strtod_works=yes],
110 [gl_cv_func_strtod_works="guessing no"])])])
111 if test "$gl_cv_func_strtod_works" != yes; then
115 if test $HAVE_STRTOD = 0 || test $REPLACE_STRTOD = 1; then
121 # Prerequisites of lib/strtod.c.
122 AC_DEFUN([gl_PREREQ_STRTOD], [
123 AC_REQUIRE([gl_CHECK_LDEXP_NO_LIBM])
124 if test $gl_cv_func_ldexp_no_libm = yes; then
125 AC_DEFINE([HAVE_LDEXP_IN_LIBC], [1],
126 [Define if the ldexp function is available in libc.])