strtod: avoid C99 decl-after-statement
[gnulib.git] / m4 / strtod.m4
1 # strtod.m4 serial 12
2 dnl Copyright (C) 2002-2003, 2006-2009 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.
6
7 AC_DEFUN([gl_FUNC_STRTOD],
8 [
9   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10   AC_FUNC_STRTOD
11   dnl Note: AC_FUNC_STRTOD does AC_LIBOBJ([strtod]).
12   if test $ac_cv_func_strtod = no; then
13     HAVE_STRTOD=0
14     REPLACE_STRTOD=1
15     gl_PREREQ_STRTOD
16   else
17     AC_CACHE_CHECK([whether strtod obeys C99], [gl_cv_func_strtod_works],
18       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
19 #include <stdlib.h>
20 #include <math.h>
21 #include <errno.h>
22 /* Compare two numbers with ==.
23    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
24    'x == x' test.  */
25 static int
26 numeric_equal (double x, double y)
27 {
28   return x == y;
29 }
30 ]], [[
31   {
32     /* Older glibc and Cygwin mis-parse "-0x".  */
33     const char *string = "-0x";
34     char *term;
35     double value = strtod (string, &term);
36     double zero = 0.0;
37     if (1.0 / value != -1.0 / zero || term != (string + 2))
38       return 1;
39   }
40   {
41     /* Many platforms do not parse hex floats.  */
42     const char *string = "0XaP+1";
43     char *term;
44     double value = strtod (string, &term);
45     if (value != 20.0 || term != (string + 6))
46       return 1;
47   }
48   {
49     /* Many platforms do not parse infinities.  HP-UX 11.31 parses inf,
50        but mistakenly sets errno.  */
51     const char *string = "inf";
52     char *term;
53     double value;
54     errno = 0;
55     value = strtod (string, &term);
56     if (value != HUGE_VAL || term != (string + 3) || errno)
57       return 1;
58   }
59   {
60     /* glibc 2.7 and cygwin 1.5.24 misparse "nan()".  */
61     const char *string = "nan()";
62     char *term;
63     double value = strtod (string, &term);
64     if (numeric_equal (value, value) || term != (string + 5))
65       return 1;
66   }
67 ]])],
68         [gl_cv_func_strtod_works=yes],
69         [gl_cv_func_strtod_works=no],
70         [gl_cv_func_strtod_works="guessing no"])])
71     if test "$gl_cv_func_strtod_works" != yes; then
72       REPLACE_STRTOD=1
73       gl_PREREQ_STRTOD
74       dnl Use undocumented macro to set POW_LIB correctly.
75       _AC_LIBOBJ_STRTOD
76     fi
77   fi
78 ])
79
80 # Prerequisites of lib/strtod.c.
81 # The need for pow() is already handled by AC_FUNC_STRTOD.
82 AC_DEFUN([gl_PREREQ_STRTOD], [:])