2 dnl Copyright (C) 2007-2011 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
36 AC_SUBST([ISNANL_LIBM])
39 AC_DEFUN([gl_FUNC_ISNANL_NO_LIBM],
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
45 case "$gl_cv_func_isnanl_works" in
47 *) gl_func_isnanl_no_libm=no ;;
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.])
58 dnl Pull in replacement isnanl definition. It does not need -lm.
59 AC_DEFUN([gl_BUILD_ISNANL],
62 gl_LONG_DOUBLE_EXPONENT_LOCATION
65 dnl Test whether isnanl() can be used without libm.
66 AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM],
68 AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm],
69 [gl_cv_func_isnanl_no_libm],
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],
101 # define isnanl(x) __builtin_isnanl ((long double)(x))
104 # define isnanl(x) isnan ((long double)(x))
107 [[return isnanl (x);]])],
108 [gl_cv_func_isnanl_in_libm=yes],
109 [gl_cv_func_isnanl_in_libm=no])
114 dnl Test whether isnanl() recognizes all numbers which are neither finite nor
115 dnl infinite. This test fails e.g. on NetBSD/i386 and on glibc/ia64.
116 dnl Also, the GCC >= 4.0 built-in __builtin_isnanl does not pass the tests
117 dnl - for pseudo-denormals on i686 and x86_64,
118 dnl - for pseudo-zeroes, unnormalized numbers, and pseudo-denormals on ia64.
119 AC_DEFUN([gl_FUNC_ISNANL_WORKS],
121 AC_REQUIRE([AC_PROG_CC])
122 AC_REQUIRE([gl_BIGENDIAN])
123 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
124 AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works],
133 # define isnanl(x) __builtin_isnanl ((long double)(x))
136 # define isnanl(x) isnan ((long double)(x))
139 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
140 typedef union { unsigned int word[NWORDS]; long double value; }
142 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
143 runtime type conversion. */
145 static long double NaNl ()
151 # define NaNl() (0.0L / 0.0L)
157 if (!isnanl (NaNl ()))
161 memory_long_double m;
164 /* The isnanl function should be immune against changes in the sign bit and
165 in the mantissa bits. The xor operation twiddles a bit that can only be
166 a sign bit or a mantissa bit (since the exponent never extends to
169 m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
170 for (i = 0; i < NWORDS; i++)
172 if (!isnanl (m.value))
176 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
177 /* Representation of an 80-bit 'long double' as an initializer for a sequence
178 of 'unsigned int' words. */
179 # ifdef WORDS_BIGENDIAN
180 # define LDBL80_WORDS(exponent,manthi,mantlo) \
181 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
182 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
183 (unsigned int) (mantlo) << 16 \
186 # define LDBL80_WORDS(exponent,manthi,mantlo) \
187 { mantlo, manthi, exponent }
190 static memory_long_double x =
191 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
192 if (!isnanl (x.value))
196 /* Signalling NaN. */
197 static memory_long_double x =
198 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
199 if (!isnanl (x.value))
202 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
203 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
204 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
205 Application Architecture.
206 Table 5-2 "Floating-Point Register Encodings"
207 Figure 5-6 "Memory to Floating-Point Register Data Translation"
210 static memory_long_double x =
211 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
212 if (!isnanl (x.value))
215 { /* Pseudo-Infinity. */
216 static memory_long_double x =
217 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
218 if (!isnanl (x.value))
222 static memory_long_double x =
223 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
224 if (!isnanl (x.value))
227 { /* Unnormalized number. */
228 static memory_long_double x =
229 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
230 if (!isnanl (x.value))
233 { /* Pseudo-Denormal. */
234 static memory_long_double x =
235 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
236 if (!isnanl (x.value))
243 [gl_cv_func_isnanl_works=yes],
244 [gl_cv_func_isnanl_works=no],
246 # Guess no on ia64, x86_64, i386.
247 ia64 | x86_64 | i*86) gl_cv_func_isnanl_works="guessing no";;
250 netbsd*) gl_cv_func_isnanl_works="guessing no";;
251 *) gl_cv_func_isnanl_works="guessing yes";;