Merge branch 'upstream' into stable
[gnulib.git] / m4 / strtod.m4
1 # strtod.m4 serial 14
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.
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     gl_PREREQ_STRTOD
15   else
16     AC_CACHE_CHECK([whether strtod obeys C99], [gl_cv_func_strtod_works],
17       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
18 #include <stdlib.h>
19 #include <math.h>
20 #include <errno.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.  HP-UX 11.31 parses inf,
49        but mistakenly sets errno.  */
50     const char *string = "inf";
51     char *term;
52     double value;
53     errno = 0;
54     value = strtod (string, &term);
55     if (value != HUGE_VAL || term != (string + 3) || errno)
56       return 1;
57   }
58   {
59     /* glibc 2.7 and cygwin 1.5.24 misparse "nan()".  */
60     const char *string = "nan()";
61     char *term;
62     double value = strtod (string, &term);
63     if (numeric_equal (value, value) || term != (string + 5))
64       return 1;
65   }
66   {
67     /* darwin 10.6.1 misparses "nan(".  */
68     const char *string = "nan(";
69     char *term;
70     double value = strtod (string, &term);
71     if (numeric_equal (value, value) || term != (string + 3))
72       return 1;
73   }
74 ]])],
75         [gl_cv_func_strtod_works=yes],
76         [gl_cv_func_strtod_works=no],
77         [gl_cv_func_strtod_works="guessing no"])])
78     if test "$gl_cv_func_strtod_works" != yes; then
79       REPLACE_STRTOD=1
80       gl_PREREQ_STRTOD
81       dnl Use undocumented macro to set POW_LIB correctly.
82       _AC_LIBOBJ_STRTOD
83     fi
84   fi
85 ])
86
87 # Prerequisites of lib/strtod.c.
88 # The need for pow() is already handled by AC_FUNC_STRTOD.
89 AC_DEFUN([gl_PREREQ_STRTOD], [:])