Improve strtod bug detection check.
[pspp] / m4 / strtod.m4
1 # strtod.m4 serial 8
2 dnl Copyright (C) 2002, 2003, 2006, 2007, 2008 Free Software
3 dnl Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7
8 AC_DEFUN([gl_FUNC_STRTOD],
9 [
10   AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
11   AC_FUNC_STRTOD
12   dnl Note: AC_FUNC_STRTOD does AC_LIBOBJ(strtod).
13   if test $ac_cv_func_strtod = no; then
14     HAVE_STRTOD=0
15     REPLACE_STRTOD=1
16     gl_PREREQ_STRTOD
17   else
18     AC_CACHE_CHECK([whether strtod obeys C99], [gl_cv_func_strtod_works],
19       [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
20 #include <stdlib.h>
21 #include <math.h>
22 ]], [[
23   {
24     /* Older glibc and Cygwin mis-parse "-0x".  */
25     const char *string = "-0x";
26     char *term;
27     double value = strtod (string, &term);
28     if (1 / value != -HUGE_VAL || term != (string + 2))
29       return 1;
30   }
31   {
32     /* Many platforms do not parse hex floats.  */
33     const char *string = "0XaP+1";
34     char *term;
35     double value = strtod (string, &term);
36     if (value != 20.0 || term != (string + 6))
37       return 1;
38   }
39   {
40     /* Many platforms do not parse infinities.  */
41     const char *string = "inf";
42     char *term;
43     double value = strtod (string, &term);
44     if (value != HUGE_VAL || term != (string + 3))
45       return 1;
46   }
47 ]])],
48         [gl_cv_func_strtod_works=yes],
49         [gl_cv_func_strtod_works=no],
50         [gl_cv_func_strtod_works="guessing no"])])
51     if test "$gl_cv_func_strtod_works" != yes; then
52       REPLACE_STRTOD=1
53       gl_PREREQ_STRTOD
54       dnl Use undocumented macro to set POW_LIB correctly.
55       _AC_LIBOBJ_STRTOD
56     fi
57   fi
58 ])
59
60 # Prerequisites of lib/strtod.c.
61 # The need for pow() is already handled by AC_FUNC_STRTOD.
62 AC_DEFUN([gl_PREREQ_STRTOD], [:])