| 1 |
# isnanl.m4 |
| 2 |
# serial 27 |
| 3 |
dnl Copyright (C) 2007-2026 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_ONCE([gl_FUNC_ISNANL], |
| 10 |
[ |
| 11 |
AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 12 |
ISNANL_LIBM= |
| 13 |
gl_HAVE_ISNANL_NO_LIBM |
| 14 |
if test $gl_cv_func_isnanl_no_libm = no; then |
| 15 |
gl_HAVE_ISNANL_IN_LIBM |
| 16 |
if test $gl_cv_func_isnanl_in_libm = yes; then |
| 17 |
ISNANL_LIBM=-lm |
| 18 |
fi |
| 19 |
fi |
| 20 |
dnl The variable gl_func_isnanl set here is used by isnan.m4. |
| 21 |
if test $gl_cv_func_isnanl_no_libm = yes || test -n "$ISNANL_LIBM"; then |
| 22 |
saved_LIBS="$LIBS" |
| 23 |
LIBS="$LIBS $ISNANL_LIBM" |
| 24 |
gl_FUNC_ISNANL_WORKS |
| 25 |
LIBS="$saved_LIBS" |
| 26 |
case "$gl_cv_func_isnanl_works" in |
| 27 |
*yes) gl_func_isnanl=yes ;; |
| 28 |
*) gl_func_isnanl=no; ISNANL_LIBM= ;; |
| 29 |
esac |
| 30 |
else |
| 31 |
gl_func_isnanl=no |
| 32 |
fi |
| 33 |
if test $gl_func_isnanl != yes; then |
| 34 |
HAVE_ISNANL=0 |
| 35 |
fi |
| 36 |
AC_SUBST([ISNANL_LIBM]) |
| 37 |
]) |
| 38 |
|
| 39 |
AC_DEFUN([gl_FUNC_ISNANL_NO_LIBM], |
| 40 |
[ |
| 41 |
gl_HAVE_ISNANL_NO_LIBM |
| 42 |
gl_func_isnanl_no_libm=$gl_cv_func_isnanl_no_libm |
| 43 |
if test $gl_func_isnanl_no_libm = yes; then |
| 44 |
gl_FUNC_ISNANL_WORKS |
| 45 |
case "$gl_cv_func_isnanl_works" in |
| 46 |
*yes) ;; |
| 47 |
*) gl_func_isnanl_no_libm=no ;; |
| 48 |
esac |
| 49 |
fi |
| 50 |
if test $gl_func_isnanl_no_libm = yes; then |
| 51 |
AC_DEFINE([HAVE_ISNANL_IN_LIBC], [1], |
| 52 |
[Define if the isnan(long double) function is available in libc.]) |
| 53 |
fi |
| 54 |
]) |
| 55 |
|
| 56 |
dnl Prerequisites of replacement isnanl definition. It does not need -lm. |
| 57 |
AC_DEFUN([gl_PREREQ_ISNANL], |
| 58 |
[ |
| 59 |
gl_LONG_DOUBLE_EXPONENT_LOCATION |
| 60 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 61 |
]) |
| 62 |
|
| 63 |
dnl Test whether isnanl() can be used without libm. |
| 64 |
AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM], |
| 65 |
[ |
| 66 |
AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm], |
| 67 |
[gl_cv_func_isnanl_no_libm], |
| 68 |
[ |
| 69 |
AC_LINK_IFELSE( |
| 70 |
[AC_LANG_PROGRAM( |
| 71 |
[[#include <math.h> |
| 72 |
#if (__GNUC__ >= 4) || (__clang_major__ >= 4) |
| 73 |
# undef isnanl |
| 74 |
# define isnanl(x) __builtin_isnan ((long double)(x)) |
| 75 |
#elif defined isnan |
| 76 |
# undef isnanl |
| 77 |
# define isnanl(x) isnan ((long double)(x)) |
| 78 |
#endif |
| 79 |
long double x;]], |
| 80 |
[[return isnanl (x);]])], |
| 81 |
[gl_cv_func_isnanl_no_libm=yes], |
| 82 |
[gl_cv_func_isnanl_no_libm=no]) |
| 83 |
]) |
| 84 |
]) |
| 85 |
|
| 86 |
dnl Test whether isnanl() can be used with libm. |
| 87 |
AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM], |
| 88 |
[ |
| 89 |
AC_CACHE_CHECK([whether isnan(long double) can be used with libm], |
| 90 |
[gl_cv_func_isnanl_in_libm], |
| 91 |
[ |
| 92 |
saved_LIBS="$LIBS" |
| 93 |
LIBS="$LIBS -lm" |
| 94 |
AC_LINK_IFELSE( |
| 95 |
[AC_LANG_PROGRAM( |
| 96 |
[[#include <math.h> |
| 97 |
#if (__GNUC__ >= 4) || (__clang_major__ >= 4) |
| 98 |
# undef isnanl |
| 99 |
# define isnanl(x) __builtin_isnan ((long double)(x)) |
| 100 |
#elif defined isnan |
| 101 |
# undef isnanl |
| 102 |
# define isnanl(x) isnan ((long double)(x)) |
| 103 |
#endif |
| 104 |
long double x;]], |
| 105 |
[[return isnanl (x);]])], |
| 106 |
[gl_cv_func_isnanl_in_libm=yes], |
| 107 |
[gl_cv_func_isnanl_in_libm=no]) |
| 108 |
LIBS="$saved_LIBS" |
| 109 |
]) |
| 110 |
]) |
| 111 |
|
| 112 |
dnl Test whether isnanl() recognizes all canonical numbers which are neither |
| 113 |
dnl finite nor infinite. |
| 114 |
AC_DEFUN([gl_FUNC_ISNANL_WORKS], |
| 115 |
[ |
| 116 |
AC_REQUIRE([AC_PROG_CC]) |
| 117 |
AC_REQUIRE([gl_BIGENDIAN]) |
| 118 |
AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE]) |
| 119 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 120 |
AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works], |
| 121 |
[ |
| 122 |
AC_RUN_IFELSE( |
| 123 |
[AC_LANG_SOURCE([[ |
| 124 |
#include <float.h> |
| 125 |
#include <limits.h> |
| 126 |
#include <math.h> |
| 127 |
#if (__GNUC__ >= 4) || (__clang_major__ >= 4) |
| 128 |
# undef isnanl |
| 129 |
# define isnanl(x) __builtin_isnan ((long double)(x)) |
| 130 |
#elif defined isnan |
| 131 |
# undef isnanl |
| 132 |
# define isnanl(x) isnan ((long double)(x)) |
| 133 |
#endif |
| 134 |
#define NWORDS \ |
| 135 |
((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int)) |
| 136 |
typedef union { unsigned int word[NWORDS]; long double value; } |
| 137 |
memory_long_double; |
| 138 |
#define NaNl() (0.0L / 0.0L) |
| 139 |
int main () |
| 140 |
{ |
| 141 |
int result = 0; |
| 142 |
|
| 143 |
if (!isnanl (NaNl ())) |
| 144 |
result |= 1; |
| 145 |
|
| 146 |
{ |
| 147 |
memory_long_double m; |
| 148 |
unsigned int i; |
| 149 |
|
| 150 |
/* The isnanl function should be immune against changes in the sign bit and |
| 151 |
in the mantissa bits. The xor operation twiddles a bit that can only be |
| 152 |
a sign bit or a mantissa bit (since the exponent never extends to |
| 153 |
bit 31). */ |
| 154 |
m.value = NaNl (); |
| 155 |
m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1); |
| 156 |
for (i = 0; i < NWORDS; i++) |
| 157 |
m.word[i] |= 1; |
| 158 |
if (!isnanl (m.value)) |
| 159 |
result |= 1; |
| 160 |
} |
| 161 |
|
| 162 |
#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE |
| 163 |
/* Representation of an 80-bit 'long double' as an initializer for a sequence |
| 164 |
of 'unsigned int' words. */ |
| 165 |
# ifdef WORDS_BIGENDIAN |
| 166 |
# define LDBL80_WORDS(exponent,manthi,mantlo) \ |
| 167 |
{ ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \ |
| 168 |
((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \ |
| 169 |
(unsigned int) (mantlo) << 16 \ |
| 170 |
} |
| 171 |
# else |
| 172 |
# define LDBL80_WORDS(exponent,manthi,mantlo) \ |
| 173 |
{ mantlo, manthi, exponent } |
| 174 |
# endif |
| 175 |
{ /* Quiet NaN. */ |
| 176 |
static memory_long_double x = |
| 177 |
{ LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) }; |
| 178 |
if (!isnanl (x.value)) |
| 179 |
result |= 2; |
| 180 |
} |
| 181 |
{ |
| 182 |
/* Signalling NaN. */ |
| 183 |
static memory_long_double x = |
| 184 |
{ LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) }; |
| 185 |
if (!isnanl (x.value)) |
| 186 |
result |= 2; |
| 187 |
} |
| 188 |
/* isnanl should return something even for noncanonical values. */ |
| 189 |
{ /* Pseudo-NaN. */ |
| 190 |
static memory_long_double x = |
| 191 |
{ LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) }; |
| 192 |
if (isnanl (x.value) && !isnanl (x.value)) |
| 193 |
result |= 4; |
| 194 |
} |
| 195 |
{ /* Pseudo-Infinity. */ |
| 196 |
static memory_long_double x = |
| 197 |
{ LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) }; |
| 198 |
if (isnanl (x.value) && !isnanl (x.value)) |
| 199 |
result |= 8; |
| 200 |
} |
| 201 |
{ /* Pseudo-Zero. */ |
| 202 |
static memory_long_double x = |
| 203 |
{ LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) }; |
| 204 |
if (isnanl (x.value) && !isnanl (x.value)) |
| 205 |
result |= 16; |
| 206 |
} |
| 207 |
{ /* Unnormalized number. */ |
| 208 |
static memory_long_double x = |
| 209 |
{ LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) }; |
| 210 |
if (isnanl (x.value) && !isnanl (x.value)) |
| 211 |
result |= 32; |
| 212 |
} |
| 213 |
{ /* Pseudo-Denormal. */ |
| 214 |
static memory_long_double x = |
| 215 |
{ LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) }; |
| 216 |
if (isnanl (x.value) && !isnanl (x.value)) |
| 217 |
result |= 64; |
| 218 |
} |
| 219 |
#endif |
| 220 |
|
| 221 |
return result; |
| 222 |
}]])], |
| 223 |
[gl_cv_func_isnanl_works=yes], |
| 224 |
[gl_cv_func_isnanl_works=no], |
| 225 |
[case "$host_os" in |
| 226 |
mingw* | windows*) # Guess yes on mingw, no on MSVC. |
| 227 |
AC_EGREP_CPP([Known], [ |
| 228 |
#ifdef __MINGW32__ |
| 229 |
Known |
| 230 |
#endif |
| 231 |
], |
| 232 |
[gl_cv_func_isnanl_works="guessing yes"], |
| 233 |
[gl_cv_func_isnanl_works="guessing no"]) |
| 234 |
;; |
| 235 |
*) gl_cv_func_isnanl_works="guessing yes" ;; |
| 236 |
esac |
| 237 |
]) |
| 238 |
]) |
| 239 |
]) |