2 dnl Copyright (C) 2007-2020 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_ISNANL],
9 AC_REQUIRE([gl_MATH_H_DEFAULTS])
11 gl_HAVE_ISNANL_NO_LIBM
12 if test $gl_cv_func_isnanl_no_libm = no; then
13 gl_HAVE_ISNANL_IN_LIBM
14 if test $gl_cv_func_isnanl_in_libm = yes; then
18 dnl The variable gl_func_isnanl set here is used by isnan.m4.
19 if test $gl_cv_func_isnanl_no_libm = yes \
20 || test $gl_cv_func_isnanl_in_libm = yes; then
22 LIBS="$LIBS $ISNANL_LIBM"
25 case "$gl_cv_func_isnanl_works" in
26 *yes) gl_func_isnanl=yes ;;
27 *) gl_func_isnanl=no; ISNANL_LIBM= ;;
32 if test $gl_func_isnanl != yes; then
35 AC_SUBST([ISNANL_LIBM])
38 AC_DEFUN([gl_FUNC_ISNANL_NO_LIBM],
40 gl_HAVE_ISNANL_NO_LIBM
41 gl_func_isnanl_no_libm=$gl_cv_func_isnanl_no_libm
42 if test $gl_func_isnanl_no_libm = yes; then
44 case "$gl_cv_func_isnanl_works" in
46 *) gl_func_isnanl_no_libm=no ;;
49 if test $gl_func_isnanl_no_libm = yes; then
50 AC_DEFINE([HAVE_ISNANL_IN_LIBC], [1],
51 [Define if the isnan(long double) function is available in libc.])
55 dnl Prerequisites of replacement isnanl definition. It does not need -lm.
56 AC_DEFUN([gl_PREREQ_ISNANL],
58 gl_LONG_DOUBLE_EXPONENT_LOCATION
59 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
62 dnl Test whether isnanl() can be used without libm.
63 AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM],
65 AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm],
66 [gl_cv_func_isnanl_no_libm],
72 # define __has_builtin(name) 0
74 #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl))
76 # define isnanl(x) __builtin_isnanl ((long double)(x))
79 # define isnanl(x) isnan ((long double)(x))
82 [[return isnanl (x);]])],
83 [gl_cv_func_isnanl_no_libm=yes],
84 [gl_cv_func_isnanl_no_libm=no])
88 dnl Test whether isnanl() can be used with libm.
89 AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM],
91 AC_CACHE_CHECK([whether isnan(long double) can be used with libm],
92 [gl_cv_func_isnanl_in_libm],
100 # define __has_builtin(name) 0
102 #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl))
104 # define isnanl(x) __builtin_isnanl ((long double)(x))
107 # define isnanl(x) isnan ((long double)(x))
110 [[return isnanl (x);]])],
111 [gl_cv_func_isnanl_in_libm=yes],
112 [gl_cv_func_isnanl_in_libm=no])
117 dnl Test whether isnanl() recognizes all canonical numbers which are neither
118 dnl finite nor infinite.
119 AC_DEFUN([gl_FUNC_ISNANL_WORKS],
121 AC_REQUIRE([AC_PROG_CC])
122 AC_REQUIRE([gl_BIGENDIAN])
123 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
124 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
125 AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works],
132 #ifndef __has_builtin
133 # define __has_builtin(name) 0
135 #if __GNUC__ >= 4 && (!defined __clang__ || __has_builtin (__builtin_isnanl))
137 # define isnanl(x) __builtin_isnanl ((long double)(x))
140 # define isnanl(x) isnan ((long double)(x))
143 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
144 typedef union { unsigned int word[NWORDS]; long double value; }
146 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
147 runtime type conversion. */
149 static long double NaNl ()
155 # define NaNl() (0.0L / 0.0L)
161 if (!isnanl (NaNl ()))
165 memory_long_double m;
168 /* The isnanl function should be immune against changes in the sign bit and
169 in the mantissa bits. The xor operation twiddles a bit that can only be
170 a sign bit or a mantissa bit (since the exponent never extends to
173 m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
174 for (i = 0; i < NWORDS; i++)
176 if (!isnanl (m.value))
180 #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
181 /* Representation of an 80-bit 'long double' as an initializer for a sequence
182 of 'unsigned int' words. */
183 # ifdef WORDS_BIGENDIAN
184 # define LDBL80_WORDS(exponent,manthi,mantlo) \
185 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
186 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
187 (unsigned int) (mantlo) << 16 \
190 # define LDBL80_WORDS(exponent,manthi,mantlo) \
191 { mantlo, manthi, exponent }
194 static memory_long_double x =
195 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
196 if (!isnanl (x.value))
200 /* Signalling NaN. */
201 static memory_long_double x =
202 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
203 if (!isnanl (x.value))
206 /* isnanl should return something even for noncanonical values. */
208 static memory_long_double x =
209 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
210 if (isnanl (x.value) && !isnanl (x.value))
213 { /* Pseudo-Infinity. */
214 static memory_long_double x =
215 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
216 if (isnanl (x.value) && !isnanl (x.value))
220 static memory_long_double x =
221 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
222 if (isnanl (x.value) && !isnanl (x.value))
225 { /* Unnormalized number. */
226 static memory_long_double x =
227 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
228 if (isnanl (x.value) && !isnanl (x.value))
231 { /* Pseudo-Denormal. */
232 static memory_long_double x =
233 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
234 if (isnanl (x.value) && !isnanl (x.value))
241 [gl_cv_func_isnanl_works=yes],
242 [gl_cv_func_isnanl_works=no],
244 mingw*) # Guess yes on mingw, no on MSVC.
245 AC_EGREP_CPP([Known], [
250 [gl_cv_func_isnanl_works="guessing yes"],
251 [gl_cv_func_isnanl_works="guessing no"])
253 *) gl_cv_func_isnanl_works="guessing yes" ;;