1 /* Test of isfinite() substitute.
2 Copyright (C) 2007-2012 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, 2007, using Bruno Haible's code as a
24 /* isfinite must be a macro. */
26 # error missing declaration
37 long double zerol = 0.0L;
43 ASSERT (isfinite (0.0f));
44 /* Subnormal values. */
45 ASSERT (isfinite (FLT_MIN / 2));
46 ASSERT (isfinite (-FLT_MIN / 2));
48 ASSERT (isfinite (3.141f));
49 ASSERT (isfinite (3.141e30f));
50 ASSERT (isfinite (3.141e-30f));
51 ASSERT (isfinite (-2.718f));
52 ASSERT (isfinite (-2.718e30f));
53 ASSERT (isfinite (-2.718e-30f));
54 /* Infinite values. */
55 ASSERT (!isfinite (Infinityf ()));
56 ASSERT (!isfinite (- Infinityf ()));
58 ASSERT (!isfinite (zerof / zerof));
59 #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
63 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
64 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
66 m.value = zerof / zerof;
67 # if FLT_EXPBIT0_BIT > 0
68 m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
70 m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
71 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
73 if (FLT_EXPBIT0_WORD < NWORDS / 2)
74 m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
76 m.word[0] |= (unsigned int) 1;
77 ASSERT (!isfinite (m.value));
87 ASSERT (isfinite (0.0));
88 /* Subnormal values. */
89 ASSERT (isfinite (DBL_MIN / 2));
90 ASSERT (isfinite (-DBL_MIN / 2));
92 ASSERT (isfinite (3.141));
93 ASSERT (isfinite (3.141e30));
94 ASSERT (isfinite (3.141e-30));
95 ASSERT (isfinite (-2.718));
96 ASSERT (isfinite (-2.718e30));
97 ASSERT (isfinite (-2.718e-30));
98 /* Infinite values. */
99 ASSERT (!isfinite (Infinityd ()));
100 ASSERT (!isfinite (- Infinityd ()));
102 ASSERT (!isfinite (zerod / zerod));
103 #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
104 /* Signalling NaN. */
107 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
108 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
110 m.value = zerod / zerod;
111 # if DBL_EXPBIT0_BIT > 0
112 m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
114 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
115 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
117 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
118 |= (unsigned int) 1 << DBL_EXPBIT0_BIT;
119 ASSERT (!isfinite (m.value));
129 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
130 typedef union { unsigned int word[NWORDS]; long double value; }
134 ASSERT (isfinite (0.0L));
135 /* Subnormal values. */
136 ASSERT (isfinite (LDBL_MIN / 2));
137 ASSERT (isfinite (-LDBL_MIN / 2));
139 ASSERT (isfinite (3.141L));
140 ASSERT (isfinite (3.141e30L));
141 ASSERT (isfinite (3.141e-30L));
142 ASSERT (isfinite (-2.718L));
143 ASSERT (isfinite (-2.718e30L));
144 ASSERT (isfinite (-2.718e-30L));
145 /* Infinite values. */
146 ASSERT (!isfinite (Infinityl ()));
147 ASSERT (!isfinite (- Infinityl ()));
149 ASSERT (!isfinite (zerol / zerol));
151 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
152 /* A bit pattern that is different from a Quiet NaN. With a bit of luck,
153 it's a Signalling NaN. */
155 memory_long_double m;
156 m.value = zerol / zerol;
157 # if LDBL_EXPBIT0_BIT > 0
158 m.word[LDBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT - 1);
160 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
161 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
163 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
164 |= (unsigned int) 1 << LDBL_EXPBIT0_BIT;
165 ASSERT (!isfinite (m.value));
169 #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
170 /* Representation of an 80-bit 'long double' as an initializer for a sequence
171 of 'unsigned int' words. */
172 # ifdef WORDS_BIGENDIAN
173 # define LDBL80_WORDS(exponent,manthi,mantlo) \
174 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
175 ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16), \
176 (unsigned int) (mantlo) << 16 \
179 # define LDBL80_WORDS(exponent,manthi,mantlo) \
180 { mantlo, manthi, exponent }
183 static memory_long_double x =
184 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
185 ASSERT (!isfinite (x.value));
188 /* Signalling NaN. */
189 static memory_long_double x =
190 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
191 ASSERT (!isfinite (x.value));
193 /* The isnanl function should recognize Pseudo-NaNs, Pseudo-Infinities,
194 Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals, as defined in
195 Intel IA-64 Architecture Software Developer's Manual, Volume 1:
196 Application Architecture.
197 Table 5-2 "Floating-Point Register Encodings"
198 Figure 5-6 "Memory to Floating-Point Register Data Translation"
201 static memory_long_double x =
202 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
203 ASSERT (!isfinite (x.value));
205 { /* Pseudo-Infinity. */
206 static memory_long_double x =
207 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
208 ASSERT (!isfinite (x.value));
211 static memory_long_double x =
212 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
213 ASSERT (!isfinite (x.value));
215 { /* Unnormalized number. */
216 static memory_long_double x =
217 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
218 ASSERT (!isfinite (x.value));
220 { /* Pseudo-Denormal. */
221 static memory_long_double x =
222 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
223 ASSERT (!isfinite (x.value));