powerpc: Fix __arch_compare_and_exchange_bool_64_rel
[glibc.git] / math / bug-nextafter.c
blobd48bca288d63f001a6ee82dbe70f5b11256145e5
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 #ifndef NO_LONG_DOUBLE
223 long double li = INFINITY;
224 long double lm = LDBL_MAX;
225 feclearexcept (FE_ALL_EXCEPT);
226 if (nextafterl (lm, li) != li)
228 puts ("nextafterl+ failed");
229 ++result;
231 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW) == 0)
233 puts ("nextafterl+ did not overflow");
234 ++result;
236 feclearexcept (FE_ALL_EXCEPT);
237 if (nextafterl (-lm, -li) != -li)
239 puts ("nextafterl failed");
240 ++result;
242 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW) == 0)
244 puts ("nextafterl- did not overflow");
245 ++result;
248 li = 0;
249 lm = LDBL_MIN;
250 feclearexcept (FE_ALL_EXCEPT);
251 li = nextafterl (lm, li);
252 if (li < 0 || li >= LDBL_MIN)
254 puts ("nextafterl+ failed");
255 ++result;
257 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
259 puts ("nextafterl+ did not underflow");
260 ++result;
262 li = 0;
263 feclearexcept (FE_ALL_EXCEPT);
264 li = nextafterl (-lm, -li);
265 if (li > 0 || li <= -LDBL_MIN)
267 puts ("nextafterl- failed");
268 ++result;
270 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
272 puts ("nextafterl- did not underflow");
273 ++result;
275 li = -INFINITY;
276 feclearexcept (FE_ALL_EXCEPT);
277 lm = nextafterl (zero, inf);
278 if (lm < 0.0 || lm >= LDBL_MIN)
280 puts ("nextafterl+ failed");
281 ++result;
283 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
285 puts ("nextafterl+ did not underflow");
286 ++result;
288 feclearexcept (FE_ALL_EXCEPT);
289 if (nextafterl (lm, li) != 0.0)
291 puts ("nextafterl+ failed");
292 ++result;
294 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
296 puts ("nextafterl+ did not underflow");
297 ++result;
299 feclearexcept (FE_ALL_EXCEPT);
300 lm = nextafterl (copysign (zero, -1.0), -inf);
301 if (lm > 0.0 || lm <= -LDBL_MIN)
303 puts ("nextafterl- failed");
304 ++result;
306 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
308 puts ("nextafterl- did not underflow");
309 ++result;
311 feclearexcept (FE_ALL_EXCEPT);
312 if (nextafterl (lm, -li) != 0.0)
314 puts ("nextafterl- failed");
315 ++result;
317 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
319 puts ("nextafterl- did not underflow");
320 ++result;
322 #endif
324 return result;