2 dnl Copyright (C) 2002-2003, 2006-2019 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.
7 AC_DEFUN([gl_FUNC_STRTOLD],
9 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
10 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
11 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
12 AC_CHECK_FUNCS_ONCE([strtold])
13 if test $ac_cv_func_strtold != yes; then
16 AC_CACHE_CHECK([whether strtold obeys C99], [gl_cv_func_strtold_works],
17 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
21 /* Compare two numbers with ==.
22 This is a separate function because IRIX 6.5 "cc -O" miscompiles an
25 numeric_equal (long double x, long double y)
32 /* Under Solaris 2.4, strtod returns the wrong value for the
33 terminating character under some conditions. */
34 const char *string = "NaN";
36 strtod (string, &term);
37 if (term != string && *(term - 1) == 0)
41 /* Older glibc and Cygwin mis-parse "-0x". */
42 const char *string = "-0x";
44 long double value = strtold (string, &term);
45 long double zero = 0.0L;
46 if (1.0L / value != -1.0L / zero || term != (string + 2))
50 /* IRIX 6.5, mingw do not parse hex floats. */
51 const char *string = "0XaP+1";
53 long double value = strtold (string, &term);
54 if (value != 20.0L || term != (string + 6))
58 /* IRIX 6.5 does not parse infinities. HP-UX 11.31/ia64 parses inf,
59 but mistakenly sets errno. */
60 const char *string = "inf";
64 value = strtod (string, &term);
65 if (value != HUGE_VAL || term != (string + 3) || errno)
69 /* glibc-2.3.2, IRIX 6.5, mingw, Haiku misparse "nan()". */
70 const char *string = "nan()";
72 long double value = strtold (string, &term);
73 if (numeric_equal (value, value) || term != (string + 5))
77 /* Mac OS X 10.5, IRIX 6.5 misparse "nan(". */
78 const char *string = "nan(";
80 long double value = strtold (string, &term);
81 if (numeric_equal (value, value) || term != (string + 3))
86 [gl_cv_func_strtold_works=yes],
87 [gl_cv_func_strtold_works=no],
88 [dnl The last known bugs in glibc strtold(), as of this writing,
89 dnl were fixed in version 2.8
90 AC_EGREP_CPP([Lucky user],
93 #ifdef __GNU_LIBRARY__
94 #if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) || (__GLIBC__ > 2)) \
95 && !defined __UCLIBC__
100 [gl_cv_func_strtold_works="guessing yes"],
101 [gl_cv_func_strtod_works="guessing no"])
104 case "$gl_cv_func_strtold_works" in
113 # Prerequisites of lib/strtold.c.
114 AC_DEFUN([gl_PREREQ_STRTOLD], [
115 AC_REQUIRE([gl_CHECK_LDEXPL_NO_LIBM])
116 if test $gl_cv_func_ldexpl_no_libm = yes; then
117 AC_DEFINE([HAVE_LDEXPL_IN_LIBC], [1],
118 [Define if the ldexpl function is available in libc.])
120 AC_CHECK_FUNCS([nl_langinfo])