hurd: Advertise libpthread
[glibc.git] / math / bug-nextafter.c
blob6d7212ec6ad2a44ef5365fd87e80350fd3f105a2
1 #include <fenv.h>
2 #include <math.h>
3 #include <float.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <math-tests.h>
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
14 float zero = 0.0;
15 float inf = INFINITY;
17 int
18 main (void)
20 int result = 0;
22 float i = INFINITY;
23 float m = FLT_MAX;
24 feclearexcept (FE_ALL_EXCEPT);
25 if (nextafterf (m, i) != i)
27 puts ("nextafterf+ failed");
28 ++result;
30 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW) == 0)
32 puts ("nextafterf+ did not overflow");
33 ++result;
35 feclearexcept (FE_ALL_EXCEPT);
36 if (nextafterf (-m, -i) != -i)
38 puts ("nextafterf- failed");
39 ++result;
41 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW) == 0)
43 puts ("nextafterf- did not overflow");
44 ++result;
47 i = 0;
48 m = FLT_MIN;
49 feclearexcept (FE_ALL_EXCEPT);
50 i = nextafterf (m, i);
51 if (i < 0 || i >= FLT_MIN)
53 puts ("nextafterf+ failed");
54 ++result;
56 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
58 puts ("nextafterf+ did not underflow");
59 ++result;
61 i = 0;
62 feclearexcept (FE_ALL_EXCEPT);
63 i = nextafterf (-m, -i);
64 if (i > 0 || i <= -FLT_MIN)
66 puts ("nextafterf- failed");
67 ++result;
69 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
71 puts ("nextafterf- did not underflow");
72 ++result;
74 i = -INFINITY;
75 feclearexcept (FE_ALL_EXCEPT);
76 m = nextafterf (zero, inf);
77 if (m < 0.0 || m >= FLT_MIN)
79 puts ("nextafterf+ failed");
80 ++result;
82 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
84 puts ("nextafterf+ did not underflow");
85 ++result;
87 feclearexcept (FE_ALL_EXCEPT);
88 if (nextafterf (m, i) != 0.0)
90 puts ("nextafterf+ failed");
91 ++result;
93 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
95 puts ("nextafterf+ did not underflow");
96 ++result;
98 feclearexcept (FE_ALL_EXCEPT);
99 m = nextafterf (copysignf (zero, -1.0), -inf);
100 if (m > 0.0 || m <= -FLT_MIN)
102 puts ("nextafterf- failed");
103 ++result;
105 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
107 puts ("nextafterf- did not underflow");
108 ++result;
110 feclearexcept (FE_ALL_EXCEPT);
111 if (nextafterf (m, -i) != 0.0)
113 puts ("nextafterf- failed");
114 ++result;
116 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
118 puts ("nextafterf- did not underflow");
119 ++result;
122 double di = INFINITY;
123 double dm = DBL_MAX;
124 feclearexcept (FE_ALL_EXCEPT);
125 if (nextafter (dm, di) != di)
127 puts ("nextafter+ failed");
128 ++result;
130 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW) == 0)
132 puts ("nextafter+ did not overflow");
133 ++result;
135 feclearexcept (FE_ALL_EXCEPT);
136 if (nextafter (-dm, -di) != -di)
138 puts ("nextafter failed");
139 ++result;
141 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW) == 0)
143 puts ("nextafter- did not overflow");
144 ++result;
147 di = 0;
148 dm = DBL_MIN;
149 feclearexcept (FE_ALL_EXCEPT);
150 di = nextafter (dm, di);
151 if (di < 0 || di >= DBL_MIN)
153 puts ("nextafter+ failed");
154 ++result;
156 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
158 puts ("nextafter+ did not underflow");
159 ++result;
161 di = 0;
162 feclearexcept (FE_ALL_EXCEPT);
163 di = nextafter (-dm, -di);
164 if (di > 0 || di <= -DBL_MIN)
166 puts ("nextafter- failed");
167 ++result;
169 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
171 puts ("nextafter- did not underflow");
172 ++result;
174 di = -INFINITY;
175 feclearexcept (FE_ALL_EXCEPT);
176 dm = nextafter (zero, inf);
177 if (dm < 0.0 || dm >= DBL_MIN)
179 puts ("nextafter+ failed");
180 ++result;
182 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
184 puts ("nextafter+ did not underflow");
185 ++result;
187 feclearexcept (FE_ALL_EXCEPT);
188 if (nextafter (dm, di) != 0.0)
190 puts ("nextafter+ failed");
191 ++result;
193 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
195 puts ("nextafter+ did not underflow");
196 ++result;
198 feclearexcept (FE_ALL_EXCEPT);
199 dm = nextafter (copysign (zero, -1.0), -inf);
200 if (dm > 0.0 || dm <= -DBL_MIN)
202 puts ("nextafter- failed");
203 ++result;
205 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
207 puts ("nextafter- did not underflow");
208 ++result;
210 feclearexcept (FE_ALL_EXCEPT);
211 if (nextafter (dm, -di) != 0.0)
213 puts ("nextafter- failed");
214 ++result;
216 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
218 puts ("nextafter- did not underflow");
219 ++result;
222 long double li = INFINITY;
223 long double lm = LDBL_MAX;
224 feclearexcept (FE_ALL_EXCEPT);
225 if (nextafterl (lm, li) != li)
227 puts ("nextafterl+ failed");
228 ++result;
230 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW) == 0)
232 puts ("nextafterl+ did not overflow");
233 ++result;
235 feclearexcept (FE_ALL_EXCEPT);
236 if (nextafterl (-lm, -li) != -li)
238 puts ("nextafterl failed");
239 ++result;
241 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW) == 0)
243 puts ("nextafterl- did not overflow");
244 ++result;
247 li = 0;
248 lm = LDBL_MIN;
249 feclearexcept (FE_ALL_EXCEPT);
250 li = nextafterl (lm, li);
251 if (li < 0 || li >= LDBL_MIN)
253 puts ("nextafterl+ failed");
254 ++result;
256 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
258 puts ("nextafterl+ did not underflow");
259 ++result;
261 li = 0;
262 feclearexcept (FE_ALL_EXCEPT);
263 li = nextafterl (-lm, -li);
264 if (li > 0 || li <= -LDBL_MIN)
266 puts ("nextafterl- failed");
267 ++result;
269 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
271 puts ("nextafterl- did not underflow");
272 ++result;
274 li = -INFINITY;
275 feclearexcept (FE_ALL_EXCEPT);
276 lm = nextafterl (zero, inf);
277 if (lm < 0.0 || lm >= LDBL_MIN)
279 puts ("nextafterl+ failed");
280 ++result;
282 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
284 puts ("nextafterl+ did not underflow");
285 ++result;
287 feclearexcept (FE_ALL_EXCEPT);
288 if (nextafterl (lm, li) != 0.0)
290 puts ("nextafterl+ failed");
291 ++result;
293 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
295 puts ("nextafterl+ did not underflow");
296 ++result;
298 feclearexcept (FE_ALL_EXCEPT);
299 lm = nextafterl (copysign (zero, -1.0), -inf);
300 if (lm > 0.0 || lm <= -LDBL_MIN)
302 puts ("nextafterl- failed");
303 ++result;
305 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
307 puts ("nextafterl- did not underflow");
308 ++result;
310 feclearexcept (FE_ALL_EXCEPT);
311 if (nextafterl (lm, -li) != 0.0)
313 puts ("nextafterl- failed");
314 ++result;
316 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
318 puts ("nextafterl- did not underflow");
319 ++result;
322 return result;