many *.m4 files: improve m4 quoting
[gnulib.git] / m4 / strtod.m4
1 # strtod.m4 serial 10
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 /* Compare two numbers with ==.
22    This is a separate function because IRIX 6.5 "cc -O" miscompiles an
23    'x == x' test.  */
24 static int
25 numeric_equal (double x, double y)
26 {
27   return x == y;
28 }
29 ]], [[
30   {
31     /* Older glibc and Cygwin mis-parse "-0x".  */
32     const char *string = "-0x";
33     char *term;
34     double value = strtod (string, &term);
35     double zero = 0.0;
36     if (1.0 / value != -1.0 / zero || term != (string + 2))
37       return 1;
38   }
39   {
40     /* Many platforms do not parse hex floats.  */
41     const char *string = "0XaP+1";
42     char *term;
43     double value = strtod (string, &term);
44     if (value != 20.0 || term != (string + 6))
45       return 1;
46   }
47   {
48     /* Many platforms do not parse infinities.  */
49     const char *string = "inf";
50     char *term;
51     double value = strtod (string, &term);
52     if (value != HUGE_VAL || term != (string + 3))
53       return 1;
54   }
55   {
56     /* glibc 2.7 and cygwin 1.5.24 misparse "nan()".  */
57     const char *string = "nan()";
58     char *term;
59     double value = strtod (string, &term);
60     if (numeric_equal (value, value) || term != (string + 5))
61       return 1;
62   }
63 ]])],
64         [gl_cv_func_strtod_works=yes],
65         [gl_cv_func_strtod_works=no],
66         [gl_cv_func_strtod_works="guessing no"])])
67     if test "$gl_cv_func_strtod_works" != yes; then
68       REPLACE_STRTOD=1
69       gl_PREREQ_STRTOD
70       dnl Use undocumented macro to set POW_LIB correctly.
71       _AC_LIBOBJ_STRTOD
72     fi
73   fi
74 ])
75
76 # Prerequisites of lib/strtod.c.
77 # The need for pow() is already handled by AC_FUNC_STRTOD.
78 AC_DEFUN([gl_PREREQ_STRTOD], [:])