2 dnl Copyright (C) 2007-2010 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 if test $gl_cv_func_isnanl_no_libm = yes \
19 || test $gl_cv_func_isnanl_in_libm = yes; then
21 LIBS="$LIBS $ISNANL_LIBM"
24 case "$gl_cv_func_isnanl_works" in
25 *yes) gl_func_isnanl=yes ;;
26 *) gl_func_isnanl=no; ISNANL_LIBM= ;;
31 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.])
57 dnl Pull in replacement isnanl definition. It does not need -lm.
58 AC_DEFUN([gl_BUILD_ISNANL],
61 gl_LONG_DOUBLE_EXPONENT_LOCATION
64 dnl Test whether isnanl() can be used without libm.
65 AC_DEFUN([gl_HAVE_ISNANL_NO_LIBM],
67 AC_CACHE_CHECK([whether isnan(long double) can be used without linking with libm],
68 [gl_cv_func_isnanl_no_libm],
75 # define isnanl(x) __builtin_isnanl ((long double)(x))
78 # define isnanl(x) isnan ((long double)(x))
81 [[return isnanl (x);]])],
82 [gl_cv_func_isnanl_no_libm=yes],
83 [gl_cv_func_isnanl_no_libm=no])
87 dnl Test whether isnanl() can be used with libm.
88 AC_DEFUN([gl_HAVE_ISNANL_IN_LIBM],
90 AC_CACHE_CHECK([whether isnan(long double) can be used with libm],
91 [gl_cv_func_isnanl_in_libm],
100 # define isnanl(x) __builtin_isnanl ((long double)(x))
103 # define isnanl(x) isnan ((long double)(x))
106 [[return isnanl (x);]])],
107 [gl_cv_func_isnanl_in_libm=yes],
108 [gl_cv_func_isnanl_in_libm=no])
113 dnl Test whether isnanl() recognizes all numbers which are neither finite nor
114 dnl infinite. This test fails e.g. on NetBSD/i386 and on glibc/ia64.
115 dnl Also, the GCC >= 4.0 built-in __builtin_isnanl does not pass the tests
116 dnl - for pseudo-denormals on i686 and x86_64,
117 dnl - for pseudo-zeroes, unnormalized numbers, and pseudo-denormals on ia64.
118 AC_DEFUN([gl_FUNC_ISNANL_WORKS],
120 AC_REQUIRE([AC_PROG_CC])
121 AC_REQUIRE([gl_BIGENDIAN])
122 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
123 AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works],
131 # define isnanl(x) __builtin_isnanl ((long double)(x))
134 # define isnanl(x) isnan ((long double)(x))
137 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
138 typedef union { unsigned int word[NWORDS]; long double value; }
140 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
141 runtime type conversion. */
143 static long double NaNl ()
149 # define NaNl() (0.0L / 0.0L)
153 memory_long_double m;
156 if (!isnanl (NaNl ()))
159 /* The isnanl function should be immune against changes in the sign bit and
160 in the mantissa bits. The xor operation twiddles a bit that can only be
161 a sign bit or a mantissa bit (since the exponent never extends to
164 m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
165 for (i = 0; i < NWORDS; i++)
167 if (!isnanl (m.value))
170 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
171 /* Representation of an 80-bit 'long double' as an initializer for a sequence
172 of 'unsigned int' words. */
173 # ifdef WORDS_BIGENDIAN
174 # define LDBL80_WORDS(exponent,manthi,mantlo) \
175 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
176 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
177 (unsigned int) (mantlo) << 16 \
180 # define LDBL80_WORDS(exponent,manthi,mantlo) \
181 { mantlo, manthi, exponent }
184 static memory_long_double x =
185 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
186 if (!isnanl (x.value))
190 /* Signalling NaN. */
191 static memory_long_double x =
192 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
193 if (!isnanl (x.value))
196 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
197 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
198 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
199 Application Architecture.
200 Table 5-2 "Floating-Point Register Encodings"
201 Figure 5-6 "Memory to Floating-Point Register Data Translation"
204 static memory_long_double x =
205 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
206 if (!isnanl (x.value))
209 { /* Pseudo-Infinity. */
210 static memory_long_double x =
211 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
212 if (!isnanl (x.value))
216 static memory_long_double x =
217 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
218 if (!isnanl (x.value))
221 { /* Unnormalized number. */
222 static memory_long_double x =
223 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
224 if (!isnanl (x.value))
227 { /* Pseudo-Denormal. */
228 static memory_long_double x =
229 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
230 if (!isnanl (x.value))
236 }], [gl_cv_func_isnanl_works=yes], [gl_cv_func_isnanl_works=no],
238 # Guess no on ia64, x86_64, i386.
239 ia64 | x86_64 | i*86) gl_cv_func_isnanl_works="guessing no";;
242 netbsd*) gl_cv_func_isnanl_works="guessing no";;
243 *) gl_cv_func_isnanl_works="guessing yes";;