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
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
61 dnl Test whether isnanl() can be used without libm.
62 AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM],
64 AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm],
65 [gl_cv_func_isnanl_no_libm],
72 # define isnanl(x) __builtin_isnanl ((long double)(x))
75 # define isnanl(x) isnan ((long double)(x))
78 [[return isnanl (x);]])],
79 [gl_cv_func_isnanl_no_libm=yes],
80 [gl_cv_func_isnanl_no_libm=no])
84 dnl Test whether isnanl() can be used with libm.
85 AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM],
87 AC_CACHE_CHECK([whether isnan(long double) can be used with libm],
88 [gl_cv_func_isnanl_in_libm],
97 # define isnanl(x) __builtin_isnanl ((long double)(x))
100 # define isnanl(x) isnan ((long double)(x))
103 [[return isnanl (x);]])],
104 [gl_cv_func_isnanl_in_libm=yes],
105 [gl_cv_func_isnanl_in_libm=no])
110 dnl Test whether isnanl() recognizes all numbers which are neither finite nor
111 dnl infinite. This test fails e.g. on NetBSD/i386 and on glibc/ia64.
112 dnl Also, the GCC >= 4.0 built-in __builtin_isnanl does not pass the tests
113 dnl - for pseudo-denormals on i686 and x86_64,
114 dnl - for pseudo-zeroes, unnormalized numbers, and pseudo-denormals on ia64.
115 AC_DEFUN([gl_FUNC_ISNANL_WORKS],
117 AC_REQUIRE([AC_PROG_CC])
118 AC_REQUIRE([gl_BIGENDIAN])
119 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
120 AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works],
129 # define isnanl(x) __builtin_isnanl ((long double)(x))
132 # define isnanl(x) isnan ((long double)(x))
135 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
136 typedef union { unsigned int word[NWORDS]; long double value; }
138 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
139 runtime type conversion. */
141 static long double NaNl ()
147 # define NaNl() (0.0L / 0.0L)
153 if (!isnanl (NaNl ()))
157 memory_long_double m;
160 /* The isnanl function should be immune against changes in the sign bit and
161 in the mantissa bits. The xor operation twiddles a bit that can only be
162 a sign bit or a mantissa bit (since the exponent never extends to
165 m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
166 for (i = 0; i < NWORDS; i++)
168 if (!isnanl (m.value))
172 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
173 /* Representation of an 80-bit 'long double' as an initializer for a sequence
174 of 'unsigned int' words. */
175 # ifdef WORDS_BIGENDIAN
176 # define LDBL80_WORDS(exponent,manthi,mantlo) \
177 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
178 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
179 (unsigned int) (mantlo) << 16 \
182 # define LDBL80_WORDS(exponent,manthi,mantlo) \
183 { mantlo, manthi, exponent }
186 static memory_long_double x =
187 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
188 if (!isnanl (x.value))
192 /* Signalling NaN. */
193 static memory_long_double x =
194 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
195 if (!isnanl (x.value))
198 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
199 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
200 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
201 Application Architecture.
202 Table 5-2 "Floating-Point Register Encodings"
203 Figure 5-6 "Memory to Floating-Point Register Data Translation"
206 static memory_long_double x =
207 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
208 if (!isnanl (x.value))
211 { /* Pseudo-Infinity. */
212 static memory_long_double x =
213 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
214 if (!isnanl (x.value))
218 static memory_long_double x =
219 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
220 if (!isnanl (x.value))
223 { /* Unnormalized number. */
224 static memory_long_double x =
225 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
226 if (!isnanl (x.value))
229 { /* Pseudo-Denormal. */
230 static memory_long_double x =
231 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
232 if (!isnanl (x.value))
239 [gl_cv_func_isnanl_works=yes],
240 [gl_cv_func_isnanl_works=no],
242 # Guess no on ia64, x86_64, i386.
243 ia64 | x86_64 | i*86) gl_cv_func_isnanl_works="guessing no";;
246 netbsd*) gl_cv_func_isnanl_works="guessing no";;
247 *) gl_cv_func_isnanl_works="guessing yes";;