Debian Codegraph @

m4/isinf.m4

raw
1 # isinf.m4
2 # serial 15
3 dnl Copyright (C) 2007-2025 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_ISINF],
10 [
11 AC_REQUIRE([gl_MATH_H_DEFAULTS])
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 dnl Persuade glibc <math.h> to declare isinf.
14 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_DECLS([isinf], , ,
16 [[#include <math.h>
17 #ifndef isinf
18 #error "isinf must be a macro, not a function"
19 #endif
20 ]])
21 if test "$ac_cv_have_decl_isinf" = yes; then
22 gl_CHECK_MATH_LIB([ISINF_LIBM], [double],
23 [x = isinf (x) + isinf ((float) x);])
24 if test "$ISINF_LIBM" != missing; then
25 dnl Test whether isinf() on 'long double' works.
26 gl_ISINFL_WORKS
27 case "$gl_cv_func_isinfl_works" in
28 *yes) ;;
29 *) ISINF_LIBM=missing;;
30 esac
31 fi
32 fi
33 dnl On Solaris 10, with CC in C++ mode, isinf is not available although
34 dnl is with cc in C mode. This cannot be worked around by defining
35 dnl _XOPEN_SOURCE=600, because the latter does not work in C++ mode on
36 dnl Solaris 11.0. Therefore use the replacement functions on Solaris.
37 if test "$ac_cv_have_decl_isinf" != yes \
38 || test "$ISINF_LIBM" = missing \
39 || { case "$host_os" in solaris*) true;; *) false;; esac; }; then
40 REPLACE_ISINF=1
41 dnl No libraries are needed to link lib/isinf.c.
42 ISINF_LIBM=
43 fi
44 AC_SUBST([ISINF_LIBM])
45 ])
46
47 dnl Test whether isinf() works:
48 dnl 1) Whether it correctly returns false for LDBL_MAX.
49 dnl 2) Whether on 'long double' recognizes all canonical values which are
50 dnl infinite.
51 AC_DEFUN([gl_ISINFL_WORKS],
52 [
53 AC_REQUIRE([AC_PROG_CC])
54 AC_REQUIRE([gl_BIGENDIAN])
55 AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
56 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
57 AC_CACHE_CHECK([whether isinf(long double) works], [gl_cv_func_isinfl_works],
58 [
59 AC_RUN_IFELSE(
60 [AC_LANG_SOURCE([[
61 #include <float.h>
62 #include <limits.h>
63 #include <math.h>
64 #define NWORDS \
65 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
66 typedef union { unsigned int word[NWORDS]; long double value; }
67 memory_long_double;
68 /* On Irix 6.5, gcc 3.4.3 can't compute compile-time NaN, and needs the
69 runtime type conversion. */
70 #ifdef __sgi
71 static long double NaNl ()
72 {
73 double zero = 0.0;
74 return zero / zero;
75 }
76 #else
77 # define NaNl() (0.0L / 0.0L)
78 #endif
79 int main ()
80 {
81 int result = 0;
82
83 if (isinf (LDBL_MAX))
84 result |= 1;
85
86 {
87 memory_long_double m;
88 unsigned int i;
89
90 /* The isinf macro should be immune against changes in the sign bit and
91 in the mantissa bits. The xor operation twiddles a bit that can only be
92 a sign bit or a mantissa bit (since the exponent never extends to
93 bit 31). */
94 m.value = NaNl ();
95 m.word[NWORDS / 2] ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
96 for (i = 0; i < NWORDS; i++)
97 m.word[i] |= 1;
98 if (isinf (m.value))
99 result |= 2;
100 }
101
102 #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
103 /* Representation of an 80-bit 'long double' as an initializer for a sequence
104 of 'unsigned int' words. */
105 # ifdef WORDS_BIGENDIAN
106 # define LDBL80_WORDS(exponent,manthi,mantlo) \
107 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
108 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
109 (unsigned int) (mantlo) << 16 \
110 }
111 # else
112 # define LDBL80_WORDS(exponent,manthi,mantlo) \
113 { mantlo, manthi, exponent }
114 # endif
115 { /* Quiet NaN. */
116 static memory_long_double x =
117 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
118 if (isinf (x.value))
119 result |= 2;
120 }
121 {
122 /* Signalling NaN. */
123 static memory_long_double x =
124 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
125 if (isinf (x.value))
126 result |= 2;
127 }
128 /* isinf should return something even for noncanonical values. */
129 { /* Pseudo-NaN. */
130 static memory_long_double x =
131 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
132 if (isinf (x.value) && !isinf (x.value))
133 result |= 4;
134 }
135 { /* Pseudo-Infinity. */
136 static memory_long_double x =
137 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
138 if (isinf (x.value) && !isinf (x.value))
139 result |= 8;
140 }
141 { /* Pseudo-Zero. */
142 static memory_long_double x =
143 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
144 if (isinf (x.value) && !isinf (x.value))
145 result |= 16;
146 }
147 { /* Unnormalized number. */
148 static memory_long_double x =
149 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
150 if (isinf (x.value) && !isinf (x.value))
151 result |= 32;
152 }
153 { /* Pseudo-Denormal. */
154 static memory_long_double x =
155 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
156 if (isinf (x.value) && !isinf (x.value))
157 result |= 64;
158 }
159 #endif
160
161 return result;
162 }]])],
163 [gl_cv_func_isinfl_works=yes],
164 [gl_cv_func_isinfl_works=no],
165 [case "$host_os" in
166 mingw* | windows*) # Guess yes on mingw, no on MSVC.
167 AC_EGREP_CPP([Known], [
168 #ifdef __MINGW32__
169 Known
170 #endif
171 ],
172 [gl_cv_func_isinfl_works="guessing yes"],
173 [gl_cv_func_isinfl_works="guessing no"])
174 ;;
175 *)
176 gl_cv_func_isinfl_works="guessing yes"
177 ;;
178 esac
179 ])
180 ])
181 ])