]>
Commit | Line | Data |
---|---|---|
07449987 | 1 | #include <fenv.h> |
64b02fd2 UD |
2 | #include <math.h> |
3 | #include <float.h> | |
4 | #include <stdlib.h> | |
5 | #include <stdio.h> | |
94f2c076 | 6 | #include <math-tests.h> |
64b02fd2 | 7 | |
0af797de CM |
8 | #if !defined(FE_OVERFLOW) && !defined(FE_UNDERFLOW) |
9 | /* If there's no support for the exceptions this test is checking, | |
10 | then just return success and allow the test to be compiled. */ | |
11 | # define fetestexcept(e) 1 | |
12 | #endif | |
13 | ||
3e336a87 UD |
14 | float zero = 0.0; |
15 | float inf = INFINITY; | |
16 | ||
64b02fd2 UD |
17 | int |
18 | main (void) | |
19 | { | |
20 | int result = 0; | |
21 | ||
22 | float i = INFINITY; | |
23 | float m = FLT_MAX; | |
07449987 | 24 | feclearexcept (FE_ALL_EXCEPT); |
64b02fd2 UD |
25 | if (nextafterf (m, i) != i) |
26 | { | |
07449987 UD |
27 | puts ("nextafterf+ failed"); |
28 | ++result; | |
29 | } | |
94f2c076 | 30 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW) == 0) |
07449987 UD |
31 | { |
32 | puts ("nextafterf+ did not overflow"); | |
33 | ++result; | |
34 | } | |
35 | feclearexcept (FE_ALL_EXCEPT); | |
36 | if (nextafterf (-m, -i) != -i) | |
37 | { | |
38 | puts ("nextafterf- failed"); | |
39 | ++result; | |
40 | } | |
94f2c076 | 41 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW) == 0) |
07449987 UD |
42 | { |
43 | puts ("nextafterf- did not overflow"); | |
64b02fd2 UD |
44 | ++result; |
45 | } | |
46 | ||
3e336a87 UD |
47 | i = 0; |
48 | m = FLT_MIN; | |
49 | feclearexcept (FE_ALL_EXCEPT); | |
50 | i = nextafterf (m, i); | |
51 | if (i < 0 || i >= FLT_MIN) | |
52 | { | |
53 | puts ("nextafterf+ failed"); | |
54 | ++result; | |
55 | } | |
94f2c076 | 56 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
57 | { |
58 | puts ("nextafterf+ did not underflow"); | |
59 | ++result; | |
60 | } | |
61 | i = 0; | |
62 | feclearexcept (FE_ALL_EXCEPT); | |
63 | i = nextafterf (-m, -i); | |
64 | if (i > 0 || i <= -FLT_MIN) | |
65 | { | |
66 | puts ("nextafterf- failed"); | |
67 | ++result; | |
68 | } | |
94f2c076 | 69 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
70 | { |
71 | puts ("nextafterf- did not underflow"); | |
72 | ++result; | |
73 | } | |
74 | i = -INFINITY; | |
75 | feclearexcept (FE_ALL_EXCEPT); | |
76 | m = nextafterf (zero, inf); | |
77 | if (m < 0.0 || m >= FLT_MIN) | |
78 | { | |
79 | puts ("nextafterf+ failed"); | |
80 | ++result; | |
81 | } | |
94f2c076 | 82 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
83 | { |
84 | puts ("nextafterf+ did not underflow"); | |
85 | ++result; | |
86 | } | |
87 | feclearexcept (FE_ALL_EXCEPT); | |
88 | if (nextafterf (m, i) != 0.0) | |
89 | { | |
90 | puts ("nextafterf+ failed"); | |
91 | ++result; | |
92 | } | |
94f2c076 | 93 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
94 | { |
95 | puts ("nextafterf+ did not underflow"); | |
96 | ++result; | |
97 | } | |
98 | feclearexcept (FE_ALL_EXCEPT); | |
99 | m = nextafterf (copysignf (zero, -1.0), -inf); | |
100 | if (m > 0.0 || m <= -FLT_MIN) | |
101 | { | |
102 | puts ("nextafterf- failed"); | |
103 | ++result; | |
104 | } | |
94f2c076 | 105 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
106 | { |
107 | puts ("nextafterf- did not underflow"); | |
108 | ++result; | |
109 | } | |
110 | feclearexcept (FE_ALL_EXCEPT); | |
111 | if (nextafterf (m, -i) != 0.0) | |
112 | { | |
113 | puts ("nextafterf- failed"); | |
114 | ++result; | |
115 | } | |
94f2c076 | 116 | if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
117 | { |
118 | puts ("nextafterf- did not underflow"); | |
119 | ++result; | |
120 | } | |
121 | ||
64b02fd2 UD |
122 | double di = INFINITY; |
123 | double dm = DBL_MAX; | |
07449987 | 124 | feclearexcept (FE_ALL_EXCEPT); |
64b02fd2 | 125 | if (nextafter (dm, di) != di) |
07449987 UD |
126 | { |
127 | puts ("nextafter+ failed"); | |
128 | ++result; | |
129 | } | |
94f2c076 | 130 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW) == 0) |
07449987 UD |
131 | { |
132 | puts ("nextafter+ did not overflow"); | |
133 | ++result; | |
134 | } | |
135 | feclearexcept (FE_ALL_EXCEPT); | |
136 | if (nextafter (-dm, -di) != -di) | |
64b02fd2 UD |
137 | { |
138 | puts ("nextafter failed"); | |
139 | ++result; | |
140 | } | |
94f2c076 | 141 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW) == 0) |
07449987 UD |
142 | { |
143 | puts ("nextafter- did not overflow"); | |
144 | ++result; | |
145 | } | |
64b02fd2 | 146 | |
3e336a87 UD |
147 | di = 0; |
148 | dm = DBL_MIN; | |
149 | feclearexcept (FE_ALL_EXCEPT); | |
150 | di = nextafter (dm, di); | |
151 | if (di < 0 || di >= DBL_MIN) | |
152 | { | |
153 | puts ("nextafter+ failed"); | |
154 | ++result; | |
155 | } | |
94f2c076 | 156 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
157 | { |
158 | puts ("nextafter+ did not underflow"); | |
159 | ++result; | |
160 | } | |
161 | di = 0; | |
162 | feclearexcept (FE_ALL_EXCEPT); | |
163 | di = nextafter (-dm, -di); | |
164 | if (di > 0 || di <= -DBL_MIN) | |
165 | { | |
166 | puts ("nextafter- failed"); | |
167 | ++result; | |
168 | } | |
94f2c076 | 169 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
170 | { |
171 | puts ("nextafter- did not underflow"); | |
172 | ++result; | |
173 | } | |
174 | di = -INFINITY; | |
175 | feclearexcept (FE_ALL_EXCEPT); | |
176 | dm = nextafter (zero, inf); | |
177 | if (dm < 0.0 || dm >= DBL_MIN) | |
178 | { | |
179 | puts ("nextafter+ failed"); | |
180 | ++result; | |
181 | } | |
94f2c076 | 182 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
183 | { |
184 | puts ("nextafter+ did not underflow"); | |
185 | ++result; | |
186 | } | |
187 | feclearexcept (FE_ALL_EXCEPT); | |
188 | if (nextafter (dm, di) != 0.0) | |
189 | { | |
190 | puts ("nextafter+ failed"); | |
191 | ++result; | |
192 | } | |
94f2c076 | 193 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
194 | { |
195 | puts ("nextafter+ did not underflow"); | |
196 | ++result; | |
197 | } | |
198 | feclearexcept (FE_ALL_EXCEPT); | |
199 | dm = nextafter (copysign (zero, -1.0), -inf); | |
200 | if (dm > 0.0 || dm <= -DBL_MIN) | |
201 | { | |
202 | puts ("nextafter- failed"); | |
203 | ++result; | |
204 | } | |
94f2c076 | 205 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
206 | { |
207 | puts ("nextafter- did not underflow"); | |
208 | ++result; | |
209 | } | |
210 | feclearexcept (FE_ALL_EXCEPT); | |
211 | if (nextafter (dm, -di) != 0.0) | |
212 | { | |
213 | puts ("nextafter- failed"); | |
214 | ++result; | |
215 | } | |
94f2c076 | 216 | if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
217 | { |
218 | puts ("nextafter- did not underflow"); | |
219 | ++result; | |
220 | } | |
221 | ||
3e336a87 UD |
222 | long double li = INFINITY; |
223 | long double lm = LDBL_MAX; | |
224 | feclearexcept (FE_ALL_EXCEPT); | |
225 | if (nextafterl (lm, li) != li) | |
226 | { | |
227 | puts ("nextafterl+ failed"); | |
228 | ++result; | |
229 | } | |
94f2c076 | 230 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW) == 0) |
3e336a87 UD |
231 | { |
232 | puts ("nextafterl+ did not overflow"); | |
233 | ++result; | |
234 | } | |
235 | feclearexcept (FE_ALL_EXCEPT); | |
236 | if (nextafterl (-lm, -li) != -li) | |
237 | { | |
238 | puts ("nextafterl failed"); | |
239 | ++result; | |
240 | } | |
94f2c076 | 241 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW) == 0) |
3e336a87 UD |
242 | { |
243 | puts ("nextafterl- did not overflow"); | |
244 | ++result; | |
245 | } | |
246 | ||
247 | li = 0; | |
248 | lm = LDBL_MIN; | |
249 | feclearexcept (FE_ALL_EXCEPT); | |
250 | li = nextafterl (lm, li); | |
251 | if (li < 0 || li >= LDBL_MIN) | |
252 | { | |
253 | puts ("nextafterl+ failed"); | |
254 | ++result; | |
255 | } | |
94f2c076 | 256 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
257 | { |
258 | puts ("nextafterl+ did not underflow"); | |
259 | ++result; | |
260 | } | |
261 | li = 0; | |
262 | feclearexcept (FE_ALL_EXCEPT); | |
263 | li = nextafterl (-lm, -li); | |
264 | if (li > 0 || li <= -LDBL_MIN) | |
265 | { | |
266 | puts ("nextafterl- failed"); | |
267 | ++result; | |
268 | } | |
94f2c076 | 269 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
270 | { |
271 | puts ("nextafterl- did not underflow"); | |
272 | ++result; | |
273 | } | |
274 | li = -INFINITY; | |
275 | feclearexcept (FE_ALL_EXCEPT); | |
276 | lm = nextafterl (zero, inf); | |
277 | if (lm < 0.0 || lm >= LDBL_MIN) | |
278 | { | |
279 | puts ("nextafterl+ failed"); | |
280 | ++result; | |
281 | } | |
94f2c076 | 282 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
283 | { |
284 | puts ("nextafterl+ did not underflow"); | |
285 | ++result; | |
286 | } | |
287 | feclearexcept (FE_ALL_EXCEPT); | |
288 | if (nextafterl (lm, li) != 0.0) | |
289 | { | |
290 | puts ("nextafterl+ failed"); | |
291 | ++result; | |
292 | } | |
94f2c076 | 293 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
294 | { |
295 | puts ("nextafterl+ did not underflow"); | |
296 | ++result; | |
297 | } | |
298 | feclearexcept (FE_ALL_EXCEPT); | |
299 | lm = nextafterl (copysign (zero, -1.0), -inf); | |
300 | if (lm > 0.0 || lm <= -LDBL_MIN) | |
301 | { | |
302 | puts ("nextafterl- failed"); | |
303 | ++result; | |
304 | } | |
94f2c076 | 305 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
306 | { |
307 | puts ("nextafterl- did not underflow"); | |
308 | ++result; | |
309 | } | |
310 | feclearexcept (FE_ALL_EXCEPT); | |
311 | if (nextafterl (lm, -li) != 0.0) | |
312 | { | |
313 | puts ("nextafterl- failed"); | |
314 | ++result; | |
315 | } | |
94f2c076 | 316 | if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0) |
3e336a87 UD |
317 | { |
318 | puts ("nextafterl- did not underflow"); | |
319 | ++result; | |
320 | } | |
3e336a87 | 321 | |
64b02fd2 UD |
322 | return result; |
323 | } |