This source file includes following definitions.
- test_isfinitef
- test_isfinited
- test_isfinitel
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include <math.h>
23
24
25 #ifndef isfinite
26 # error missing declaration
27 #endif
28
29 #include <float.h>
30 #include <limits.h>
31
32 #include "infinity.h"
33 #include "macros.h"
34
35 float zerof = 0.0f;
36 double zerod = 0.0;
37 long double zerol = 0.0L;
38
39 static void
40 test_isfinitef ()
41 {
42
43 ASSERT (isfinite (0.0f));
44
45 ASSERT (isfinite (FLT_MIN / 2));
46 ASSERT (isfinite (-FLT_MIN / 2));
47
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
55 ASSERT (!isfinite (Infinityf ()));
56 ASSERT (!isfinite (- Infinityf ()));
57
58 ASSERT (!isfinite (zerof / zerof));
59 #if defined FLT_EXPBIT0_WORD && defined FLT_EXPBIT0_BIT
60
61 {
62 #define NWORDS \
63 ((sizeof (float) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
64 typedef union { float value; unsigned int word[NWORDS]; } memory_float;
65 memory_float m;
66 m.value = zerof / zerof;
67 # if FLT_EXPBIT0_BIT > 0
68 m.word[FLT_EXPBIT0_WORD] ^= (unsigned int) 1 << (FLT_EXPBIT0_BIT - 1);
69 # else
70 m.word[FLT_EXPBIT0_WORD + (FLT_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
71 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
72 # endif
73 if (FLT_EXPBIT0_WORD < NWORDS / 2)
74 m.word[FLT_EXPBIT0_WORD + 1] |= (unsigned int) 1 << FLT_EXPBIT0_BIT;
75 else
76 m.word[0] |= (unsigned int) 1;
77 ASSERT (!isfinite (m.value));
78 #undef NWORDS
79 }
80 #endif
81 }
82
83 static void
84 test_isfinited ()
85 {
86
87 ASSERT (isfinite (0.0));
88
89 ASSERT (isfinite (DBL_MIN / 2));
90 ASSERT (isfinite (-DBL_MIN / 2));
91
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
99 ASSERT (!isfinite (Infinityd ()));
100 ASSERT (!isfinite (- Infinityd ()));
101
102 ASSERT (!isfinite (zerod / zerod));
103 #if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
104
105 {
106 #define NWORDS \
107 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
108 typedef union { double value; unsigned int word[NWORDS]; } memory_double;
109 memory_double m;
110 m.value = zerod / zerod;
111 # if DBL_EXPBIT0_BIT > 0
112 m.word[DBL_EXPBIT0_WORD] ^= (unsigned int) 1 << (DBL_EXPBIT0_BIT - 1);
113 # else
114 m.word[DBL_EXPBIT0_WORD + (DBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
115 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
116 # endif
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));
120 #undef NWORDS
121 }
122 #endif
123 }
124
125 static void
126 test_isfinitel ()
127 {
128 #define NWORDS \
129 ((sizeof (long double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
130 typedef union { unsigned int word[NWORDS]; long double value; }
131 memory_long_double;
132
133
134 ASSERT (isfinite (0.0L));
135
136 ASSERT (isfinite (LDBL_MIN / 2));
137 ASSERT (isfinite (-LDBL_MIN / 2));
138
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
146 ASSERT (!isfinite (Infinityl ()));
147 ASSERT (!isfinite (- Infinityl ()));
148
149 ASSERT (!isfinite (zerol / zerol));
150
151 #if defined LDBL_EXPBIT0_WORD && defined LDBL_EXPBIT0_BIT
152
153
154 {
155 #if defined __powerpc__ && LDBL_MANT_DIG == 106
156
157
158
159 #undef NWORDS
160 #define NWORDS \
161 ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
162 #endif
163
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);
168 # else
169 m.word[LDBL_EXPBIT0_WORD + (LDBL_EXPBIT0_WORD < NWORDS / 2 ? 1 : - 1)]
170 ^= (unsigned int) 1 << (sizeof (unsigned int) * CHAR_BIT - 1);
171 # endif
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));
175 }
176 #endif
177
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
180
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 \
186 }
187 # else
188 # define LDBL80_WORDS(exponent,manthi,mantlo) \
189 { mantlo, manthi, exponent }
190 # endif
191 {
192 static memory_long_double x =
193 { LDBL80_WORDS (0xFFFF, 0xC3333333, 0x00000000) };
194 ASSERT (!isfinite (x.value));
195 }
196 {
197
198 static memory_long_double x =
199 { LDBL80_WORDS (0xFFFF, 0x83333333, 0x00000000) };
200 ASSERT (!isfinite (x.value));
201 }
202
203 {
204 static memory_long_double x =
205 { LDBL80_WORDS (0xFFFF, 0x40000001, 0x00000000) };
206 ASSERT (isfinite (x.value) || !isfinite (x.value));
207 }
208 {
209 static memory_long_double x =
210 { LDBL80_WORDS (0xFFFF, 0x00000000, 0x00000000) };
211 ASSERT (isfinite (x.value) || !isfinite (x.value));
212 }
213 {
214 static memory_long_double x =
215 { LDBL80_WORDS (0x4004, 0x00000000, 0x00000000) };
216 ASSERT (isfinite (x.value) || !isfinite (x.value));
217 }
218 {
219 static memory_long_double x =
220 { LDBL80_WORDS (0x4000, 0x63333333, 0x00000000) };
221 ASSERT (isfinite (x.value) || !isfinite (x.value));
222 }
223 {
224 static memory_long_double x =
225 { LDBL80_WORDS (0x0000, 0x83333333, 0x00000000) };
226 ASSERT (isfinite (x.value) || !isfinite (x.value));
227 }
228 #endif
229
230 #undef NWORDS
231 }
232
233 int
234 main ()
235 {
236 test_isfinitef ();
237 test_isfinited ();
238 test_isfinitel ();
239 return 0;
240 }