1 /* Test of isfinite() substitute.
2 Copyright (C) 2007-2020 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 <https://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 #if defined __powerpc__ && LDBL_MANT_DIG == 106
156 /* This is PowerPC "double double", a pair of two doubles. Inf and Nan are
157 represented as the corresponding 64-bit IEEE values in the first double;
158 the second is ignored. Manipulate only the first double. */
161 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
164 memory_long_double m
;
165 m
.value
= zerol
/ zerol
;
166 # if LDBL_EXPBIT0_BIT > 0
167 m
.word
[LDBL_EXPBIT0_WORD
] ^= (unsigned int) 1 << (LDBL_EXPBIT0_BIT
- 1);
169 m
.word
[LDBL_EXPBIT0_WORD
+ (LDBL_EXPBIT0_WORD
< NWORDS
/ 2 ? 1 : - 1)]
170 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT
- 1);
172 m
.word
[LDBL_EXPBIT0_WORD
+ (LDBL_EXPBIT0_WORD
< NWORDS
/ 2 ? 1 : - 1)]
173 |= (unsigned int) 1 << LDBL_EXPBIT0_BIT
;
174 ASSERT (!isfinite (m
.value
));
178 #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
179 /* Representation of an 80-bit 'long double' as an initializer for a sequence
180 of 'unsigned int' words. */
181 # ifdef WORDS_BIGENDIAN
182 # define LDBL80_WORDS(exponent,manthi,mantlo) \
183 { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
184 ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16), \
185 (unsigned int) (mantlo) << 16 \
188 # define LDBL80_WORDS(exponent,manthi,mantlo) \
189 { mantlo, manthi, exponent }
192 static memory_long_double x
=
193 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
194 ASSERT (!isfinite (x
.value
));
197 /* Signalling NaN. */
198 static memory_long_double x
=
199 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
200 ASSERT (!isfinite (x
.value
));
202 /* isfinite should return something for noncanonical values. */
204 static memory_long_double x
=
205 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
206 ASSERT (isfinite (x
.value
) || !isfinite (x
.value
));
208 { /* Pseudo-Infinity. */
209 static memory_long_double x
=
210 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
211 ASSERT (isfinite (x
.value
) || !isfinite (x
.value
));
214 static memory_long_double x
=
215 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
216 ASSERT (isfinite (x
.value
) || !isfinite (x
.value
));
218 { /* Unnormalized number. */
219 static memory_long_double x
=
220 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
221 ASSERT (isfinite (x
.value
) || !isfinite (x
.value
));
223 { /* Pseudo-Denormal. */
224 static memory_long_double x
=
225 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
226 ASSERT (isfinite (x
.value
) || !isfinite (x
.value
));