Remove redundant AC_SUBST invocations.
[gnulib.git] / m4 / isfinite.m4
1 # isfinite.m4 serial 7
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.
6
7 AC_DEFUN([gl_ISFINITE],
8 [
9   AC_REQUIRE([gl_MATH_H_DEFAULTS])
10   dnl Persuade glibc <math.h> to declare isfinite.
11   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
12   AC_CHECK_DECLS([isfinite], , , [#include <math.h>])
13   if test "$ac_cv_have_decl_isfinite" = yes; then
14     gl_CHECK_MATH_LIB([ISFINITE_LIBM], [x = isfinite (x);])
15     if test "$ISFINITE_LIBM" != missing; then
16       dnl Test whether isfinite() on 'long double' works.
17       gl_ISFINITEL_WORKS
18       case "$gl_cv_func_isfinitel_works" in
19         *yes) ;;
20         *)    ISFINITE_LIBM=missing;;
21       esac
22       dnl Also, isfinite() on 'double' does not work on Linux/ia64 (because of
23       dnl signalling NaNs). But this does not have to be tested, since
24       dnl isfinite(long double) also does not work in this situation.
25     fi
26   fi
27   if test "$ac_cv_have_decl_isfinite" != yes ||
28      test "$ISFINITE_LIBM" = missing; then
29     REPLACE_ISFINITE=1
30     AC_LIBOBJ([isfinite])
31     ISFINITE_LIBM=
32   fi
33   AC_SUBST([ISFINITE_LIBM])
34 ])
35
36 dnl Test whether isfinite() on 'long double' recognizes all numbers which are
37 dnl neither finite nor infinite. This test fails e.g. on i686, x86_64, ia64,
38 dnl because of
39 dnl - pseudo-denormals on x86_64,
40 dnl - pseudo-zeroes, unnormalized numbers, and pseudo-denormals on i686,
41 dnl - pseudo-NaN, pseudo-Infinity, pseudo-zeroes, unnormalized numbers, and
42 dnl   pseudo-denormals on ia64.
43 AC_DEFUN([gl_ISFINITEL_WORKS],
44 [
45   AC_REQUIRE([AC_PROG_CC])
46   AC_REQUIRE([gl_BIGENDIAN])
47   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
48   AC_CACHE_CHECK([whether isfinite(long double) works], [gl_cv_func_isfinitel_works],
49     [
50       AC_RUN_IFELSE([AC_LANG_SOURCE([[
51 #include <float.h>
52 #include <limits.h>
53 #include <math.h>
54 #define NWORDS \
55   ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
56 typedef union { unsigned int word[NWORDS]; long double value; }
57         memory_long_double;
58 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
59    runtime type conversion.  */
60 #ifdef __sgi
61 static long double NaNl ()
62 {
63   double zero = 0.0;
64   return zero / zero;
65 }
66 #else
67 # define NaNl() (0.0L / 0.0L)
68 #endif
69 int main ()
70 {
71   memory_long_double m;
72   unsigned int i;
73
74   /* The isfinite macro should be immune against changes in the sign bit and
75      in the mantissa bits.  The xor operation twiddles a bit that can only be
76      a sign bit or a mantissa bit (since the exponent never extends to
77      bit 31).  */
78   m.value = NaNl ();
79   m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
80   for (i = 0; i < NWORDS; i++)
81     m.word[i] |= 1;
82   if (isfinite (m.value))
83     return 1;
84
85 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
86 /* Representation of an 80-bit 'long double' as an initializer for a sequence
87    of 'unsigned int' words.  */
88 # ifdef WORDS_BIGENDIAN
89 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
90      { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
91        ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),    \
92        (unsigned int) (mantlo) << 16                                        \
93      }
94 # else
95 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
96      { mantlo, manthi, exponent }
97 # endif
98   { /* Quiet NaN.  */
99     static memory_long_double x =
100       { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
101     if (isfinite (x.value))
102       return 1;
103   }
104   {
105     /* Signalling NaN.  */
106     static memory_long_double x =
107       { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
108     if (isfinite (x.value))
109       return 1;
110   }
111   /* The isfinite macro should recognize Pseudo-NaNs, Pseudo-Infinities,
112      Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
113        Intel IA-64 Architecture Software Developer's Manual, Volume 1:
114        Application Architecture.
115        Table 5-2 "Floating-Point Register Encodings"
116        Figure 5-6 "Memory to Floating-Point Register Data Translation"
117    */
118   { /* Pseudo-NaN.  */
119     static memory_long_double x =
120       { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
121     if (isfinite (x.value))
122       return 1;
123   }
124   { /* Pseudo-Infinity.  */
125     static memory_long_double x =
126       { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
127     if (isfinite (x.value))
128       return 1;
129   }
130   { /* Pseudo-Zero.  */
131     static memory_long_double x =
132       { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
133     if (isfinite (x.value))
134       return 1;
135   }
136   { /* Unnormalized number.  */
137     static memory_long_double x =
138       { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
139     if (isfinite (x.value))
140       return 1;
141   }
142   { /* Pseudo-Denormal.  */
143     static memory_long_double x =
144       { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
145     if (isfinite (x.value))
146       return 1;
147   }
148 #endif
149
150   return 0;
151 }]])], [gl_cv_func_isfinitel_works=yes], [gl_cv_func_isfinitel_works=no],
152       [case "$host_cpu" in
153                                # Guess no on ia64, x86_64, i386.
154          ia64 | x86_64 | i*86) gl_cv_func_isnanl_works="guessing no";;
155          *)                    gl_cv_func_isnanl_works="guessing yes";;
156        esac
157       ])
158     ])
159 ])