| 1 |
# strtold.m4 |
| 2 |
# serial 10 |
| 3 |
dnl Copyright (C) 2002-2003, 2006-2025 Free Software 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 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
AC_DEFUN([gl_FUNC_STRTOLD], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 12 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 13 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 14 |
AC_CHECK_FUNCS_ONCE([strtold]) |
| 15 |
if test $ac_cv_func_strtold != yes; then |
| 16 |
HAVE_STRTOLD=0 |
| 17 |
else |
| 18 |
AC_CACHE_CHECK([whether strtold obeys POSIX], [gl_cv_func_strtold_works], |
| 19 |
[AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
| 20 |
#include <stdlib.h> |
| 21 |
#include <float.h> |
| 22 |
#include <math.h> |
| 23 |
#include <errno.h> |
| 24 |
#include <string.h> |
| 25 |
/* Compare two numbers with ==. |
| 26 |
This is a separate function because IRIX 6.5 "cc -O" miscompiles an |
| 27 |
'x == x' test. */ |
| 28 |
static int |
| 29 |
numeric_equal (long double x, long double y) |
| 30 |
{ |
| 31 |
return x == y; |
| 32 |
} |
| 33 |
]], [[ |
| 34 |
int result = 0; |
| 35 |
{ |
| 36 |
/* Under Solaris 2.4, strtod returns the wrong value for the |
| 37 |
terminating character under some conditions. */ |
| 38 |
const char *string = "NaN"; |
| 39 |
char *term; |
| 40 |
strtold (string, &term); |
| 41 |
if (term != string && *(term - 1) == 0) |
| 42 |
result |= 1; |
| 43 |
} |
| 44 |
{ |
| 45 |
/* Older glibc and Cygwin mis-parse "-0x". */ |
| 46 |
const char *string = "-0x"; |
| 47 |
char *term; |
| 48 |
long double value = strtold (string, &term); |
| 49 |
long double zero = 0.0L; |
| 50 |
if (1.0L / value != -1.0L / zero || term != (string + 2)) |
| 51 |
result |= 2; |
| 52 |
} |
| 53 |
{ |
| 54 |
/* IRIX 6.5, mingw do not parse hex floats. */ |
| 55 |
const char *string = "0XaP+1"; |
| 56 |
char *term; |
| 57 |
long double value = strtold (string, &term); |
| 58 |
if (value != 20.0L || term != (string + 6)) |
| 59 |
result |= 4; |
| 60 |
} |
| 61 |
{ |
| 62 |
/* IRIX 6.5 does not parse infinities. HP-UX 11.31/ia64 parses inf, |
| 63 |
but mistakenly sets errno. */ |
| 64 |
const char *string = "inf"; |
| 65 |
char *term; |
| 66 |
long double value; |
| 67 |
errno = 0; |
| 68 |
value = strtold (string, &term); |
| 69 |
if (value != HUGE_VAL || term != (string + 3) || errno) |
| 70 |
result |= 8; |
| 71 |
} |
| 72 |
{ |
| 73 |
/* glibc-2.3.2, IRIX 6.5, mingw, Haiku misparse "nan()". */ |
| 74 |
const char *string = "nan()"; |
| 75 |
char *term; |
| 76 |
long double value = strtold (string, &term); |
| 77 |
if (numeric_equal (value, value) || term != (string + 5)) |
| 78 |
result |= 16; |
| 79 |
} |
| 80 |
{ |
| 81 |
/* Mac OS X 10.5, IRIX 6.5 misparse "nan(". */ |
| 82 |
const char *string = "nan("; |
| 83 |
char *term; |
| 84 |
long double value = strtold (string, &term); |
| 85 |
if (numeric_equal (value, value) || term != (string + 3)) |
| 86 |
result |= 16; |
| 87 |
} |
| 88 |
#ifndef _MSC_VER /* On MSVC, this is expected behaviour. */ |
| 89 |
{ |
| 90 |
/* In Cygwin 2.9 and mingw 5.0, strtold does not set errno upon |
| 91 |
gradual underflow. */ |
| 92 |
# if LDBL_MAX_EXP > 10000 |
| 93 |
const char *string = "1e-4950"; |
| 94 |
# else |
| 95 |
const char *string = "1e-320"; |
| 96 |
# endif |
| 97 |
char *term; |
| 98 |
long double value; |
| 99 |
errno = 0; |
| 100 |
value = strtold (string, &term); |
| 101 |
if (term != (string + strlen (string)) |
| 102 |
|| (value > 0.0L && value <= LDBL_MIN && errno != ERANGE)) |
| 103 |
result |= 32; |
| 104 |
} |
| 105 |
#endif |
| 106 |
{ |
| 107 |
/* In Cygwin 2.9, strtold does not set errno upon |
| 108 |
flush-to-zero underflow. */ |
| 109 |
const char *string = "1E-100000"; |
| 110 |
char *term; |
| 111 |
long double value; |
| 112 |
errno = 0; |
| 113 |
value = strtold (string, &term); |
| 114 |
if (term != (string + 9) || (value == 0.0L && errno != ERANGE)) |
| 115 |
result |= 64; |
| 116 |
} |
| 117 |
return result; |
| 118 |
]])], |
| 119 |
[gl_cv_func_strtold_works=yes], |
| 120 |
[result=$? |
| 121 |
if expr $result '>=' 64 >/dev/null; then |
| 122 |
gl_cv_func_strtold_works="no (underflow problem)" |
| 123 |
else |
| 124 |
if expr $result '>=' 32 >/dev/null; then |
| 125 |
gl_cv_func_strtold_works="no (gradual underflow problem)" |
| 126 |
else |
| 127 |
gl_cv_func_strtold_works=no |
| 128 |
fi |
| 129 |
fi |
| 130 |
], |
| 131 |
[dnl The last known bugs in glibc strtold(), as of this writing, |
| 132 |
dnl were fixed in version 2.8 |
| 133 |
AC_EGREP_CPP([Lucky user], |
| 134 |
[ |
| 135 |
#include <features.h> |
| 136 |
#ifdef __GNU_LIBRARY__ |
| 137 |
#if ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 8) || (__GLIBC__ > 2)) \ |
| 138 |
&& !defined __UCLIBC__ |
| 139 |
Lucky user |
| 140 |
#endif |
| 141 |
#endif |
| 142 |
], |
| 143 |
[gl_cv_func_strtold_works="guessing yes"], |
| 144 |
[case "$host_os" in |
| 145 |
# Guess yes on musl systems. |
| 146 |
*-musl* | midipix*) gl_cv_func_strtold_works="guessing yes" ;; |
| 147 |
# Guess 'no (underflow problem)' on Cygwin. |
| 148 |
cygwin*) gl_cv_func_strtold_works="guessing no (underflow problem)" ;; |
| 149 |
# Guess 'no (gradual underflow problem)' on mingw. |
| 150 |
# (Although the results may vary depending on |
| 151 |
# __USE_MINGW_ANSI_STDIO.) |
| 152 |
mingw* | windows*) gl_cv_func_strtold_works="guessing no (gradual underflow problem)" ;; |
| 153 |
*) gl_cv_func_strtold_works="$gl_cross_guess_normal" ;; |
| 154 |
esac |
| 155 |
]) |
| 156 |
]) |
| 157 |
]) |
| 158 |
case "$gl_cv_func_strtold_works" in |
| 159 |
*yes) ;; |
| 160 |
*) |
| 161 |
REPLACE_STRTOLD=1 |
| 162 |
case "$gl_cv_func_strtold_works" in |
| 163 |
*"no (underflow problem)") |
| 164 |
AC_DEFINE([STRTOLD_HAS_UNDERFLOW_BUG], [1], |
| 165 |
[Define to 1 if strtold does not set errno upon flush-to-zero underflow.]) |
| 166 |
;; |
| 167 |
*"no (gradual underflow problem)") |
| 168 |
AC_DEFINE([STRTOLD_HAS_GRADUAL_UNDERFLOW_PROBLEM], [1], |
| 169 |
[Define to 1 if strtold does not set errno upon gradual underflow.]) |
| 170 |
;; |
| 171 |
esac |
| 172 |
;; |
| 173 |
esac |
| 174 |
fi |
| 175 |
]) |
| 176 |
|
| 177 |
# Prerequisites of lib/strtold.c. |
| 178 |
AC_DEFUN([gl_PREREQ_STRTOLD], [ |
| 179 |
AC_REQUIRE([gl_CHECK_LDEXPL_NO_LIBM]) |
| 180 |
if test $gl_cv_func_ldexpl_no_libm = yes; then |
| 181 |
AC_DEFINE([HAVE_LDEXPL_IN_LIBC], [1], |
| 182 |
[Define if the ldexpl function is available in libc.]) |
| 183 |
fi |
| 184 |
gl_CHECK_FUNCS_ANDROID([nl_langinfo], [[#include <langinfo.h>]]) |
| 185 |
]) |