8aaf4b7930b9d053abe2e703c9cdbbfbaf97abbe
[gnulib.git] / m4 / strtod.m4
1 ## Copyright (C) 1996 Free Software Foundation, Inc.
2
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2, or (at your option)
6 ## any later version.
7
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software
15 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
16 ## 02111-1307, USA.
17
18 ## From Jim Meyering.
19
20 ## serial 1
21
22 ## @defmac AC_FUNC_STRTOD
23 ## @maindex FUNC_STRTOD
24 ## @ovindex LIBOBJS
25 ## If the @code{strtod} function is not available, or does not work
26 ## correctly (like the one on SunOS 5.4), add @samp{strtod.o} to output
27 ## variable @code{LIBOBJS}.
28 ## @end defmac
29
30 AC_DEFUN(AM_FUNC_STRTOD,
31 [AC_CACHE_CHECK(for working strtod, am_cv_func_strtod,
32 [AC_TRY_RUN([
33 double strtod ();
34 int
35 main()
36 {
37   {
38     /* Some versions of Linux strtod mis-parse strings with leading '+'.  */
39     char *string = " +69";
40     char *term;
41     double value;
42     value = strtod (string, &term);
43     if (value != 69 || term != (string + 4))
44       exit (1);
45   }
46
47   {
48     /* Under Solaris 2.4, strtod returns the wrong value for the
49        terminating character under some conditions.  */
50     char *string = "NaN";
51     char *term;
52     strtod (string, &term);
53     if (term != string && *(term - 1) == 0)
54       exit (1);
55   }
56   exit (0);
57 }
58 ], am_cv_func_strtod=yes, am_cv_func_strtod=no, am_cv_func_strtod=no)])
59 test $am_cv_func_strtod = no && LIBOBJS="$LIBOBJS strtod.o"
60 AC_SUBST(LIBOBJS)dnl
61 am_cv_func_strtod_needs_libm=no
62 if test $am_cv_func_strtod = no; then
63   AC_CHECK_FUNCS(pow)
64   if test $ac_cv_func_pow = no; then
65     AC_CHECK_LIB(m, pow, [am_cv_func_strtod_needs_libm=yes],
66                  [AC_MSG_WARN(can't find library containing definition of pow)])
67   fi
68 fi
69 ])