1 /* Test of isinf() substitute.
2 Copyright (C) 2007-2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Ben Pfaff, 2008, using Bruno Haible's code as a
29 #define ASSERT(expr) \
34 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
43 long double zerol = 0.0L;
49 ASSERT (!isinf (0.0f));
50 /* Subnormal values. */
51 ASSERT (!isinf (FLT_MIN / 2));
52 ASSERT (!isinf (-FLT_MIN / 2));
54 ASSERT (!isinf (3.141f));
55 ASSERT (!isinf (3.141e30f));
56 ASSERT (!isinf (3.141e-30f));
57 ASSERT (!isinf (-2.718f));
58 ASSERT (!isinf (-2.718e30f));
59 ASSERT (!isinf (-2.718e-30f));
60 ASSERT (!isinf (FLT_MAX));
61 ASSERT (!isinf (-FLT_MAX));
62 /* Infinite values. */
63 ASSERT (isinf (1.0f / 0.0f));
64 ASSERT (isinf (-1.0f / 0.0f));
66 ASSERT (!isinf (zerof / zerof));
67 #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
71 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
72 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
74 m.value = zerof / zerof;
75 # if FLT_EXPBIT0_BIT > 0
76 m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
78 m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
79 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
81 if (FLT_EXPBIT0_WORD < NWORDS / 2)
82 m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
84 m.word[0] |= (unsigned int) 1;
85 ASSERT (!isinf (m.value));
95 ASSERT (!isinf (0.0));
96 /* Subnormal values. */
97 ASSERT (!isinf (DBL_MIN / 2));
98 ASSERT (!isinf (-DBL_MIN / 2));
100 ASSERT (!isinf (3.141));
101 ASSERT (!isinf (3.141e30));
102 ASSERT (!isinf (3.141e-30));
103 ASSERT (!isinf (-2.718));
104 ASSERT (!isinf (-2.718e30));
105 ASSERT (!isinf (-2.718e-30));
106 ASSERT (!isinf (DBL_MAX));
107 ASSERT (!isinf (-DBL_MAX));
108 /* Infinite values. */
109 ASSERT (isinf (1.0 / 0.0));
110 ASSERT (isinf (-1.0 / 0.0));
112 ASSERT (!isinf (zerod / zerod));
113 #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
114 /* Signalling NaN. */
117 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
118 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
120 m.value = zerod / zerod;
121 # if DBL_EXPBIT0_BIT > 0
122 m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
124 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
125 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
127 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
128 |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
129 ASSERT (!isinf (m.value));
139 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
140 typedef union { unsigned int word[NWORDS]; long double value; }
144 ASSERT (!isinf (0.0L));
145 /* Subnormal values. */
146 ASSERT (!isinf (LDBL_MIN / 2));
147 ASSERT (!isinf (-LDBL_MIN / 2));
149 ASSERT (!isinf (3.141L));
150 ASSERT (!isinf (3.141e30L));
151 ASSERT (!isinf (3.141e-30L));
152 ASSERT (!isinf (-2.718L));
153 ASSERT (!isinf (-2.718e30L));
154 ASSERT (!isinf (-2.718e-30L));
155 ASSERT (!isinf (LDBL_MAX));
156 ASSERT (!isinf (-LDBL_MAX));
157 /* Infinite values. */
158 ASSERT (isinf (1.0L / 0.0L));
159 ASSERT (isinf (-1.0L / 0.0L));
161 ASSERT (!isinf (zerol / zerol));
163 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
164 /* A bit pattern that is different from a Quiet NaN. With a bit of luck,
165 it's a Signalling NaN. */
167 memory_long_double m;
168 m.value = zerol / zerol;
169 # if LDBL_EXPBIT0_BIT > 0
170 m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
172 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
173 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
175 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
176 |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
177 ASSERT (!isinf (m.value));
181 #if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
182 /* Representation of an 80-bit 'long double' as an initializer for a sequence
183 of 'unsigned int' words. */
184 # ifdef WORDS_BIGENDIAN
185 # define LDBL80_WORDS(exponent,manthi,mantlo) \
186 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
187 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
188 (unsigned int) (mantlo) << 16 \
191 # define LDBL80_WORDS(exponent,manthi,mantlo) \
192 { mantlo, manthi, exponent }
195 static memory_long_double x =
196 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
197 ASSERT (!isinf (x.value));
200 /* Signalling NaN. */
201 static memory_long_double x =
202 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
203 ASSERT (!isinf (x.value));
205 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
206 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
207 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
208 Application Architecture.
209 Table 5-2 "Floating-Point Register Encodings"
210 Figure 5-6 "Memory to Floating-Point Register Data Translation"
213 static memory_long_double x =
214 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
215 ASSERT (!isinf (x.value));
217 { /* Pseudo-Infinity. */
218 static memory_long_double x =
219 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
220 ASSERT (!isinf (x.value));
223 static memory_long_double x =
224 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
225 ASSERT (!isinf (x.value));
227 { /* Unnormalized number. */
228 static memory_long_double x =
229 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
230 ASSERT (!isinf (x.value));
232 { /* Pseudo-Denormal. */
233 static memory_long_double x =
234 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
235 ASSERT (!isinf (x.value));