PowerPC: remove branch prediction from rint implementation
[glibc.git] / math / bug-nextafter.c
blob558b1583912b8fa41551c36f12b040f09ff6cdec
1 #include <fenv.h>
2 #include <math.h>
3 #include <float.h>
4 #include <stdlib.h>
5 #include <stdio.h>
7 #if !defined(FE_OVERFLOW) && !defined(FE_UNDERFLOW)
8 /* If there's no support for the exceptions this test is checking,
9 then just return success and allow the test to be compiled. */
10 # define fetestexcept(e) 1
11 #endif
13 float zero = 0.0;
14 float inf = INFINITY;
16 int
17 main (void)
19 int result = 0;
21 float i = INFINITY;
22 float m = FLT_MAX;
23 feclearexcept (FE_ALL_EXCEPT);
24 if (nextafterf (m, i) != i)
26 puts ("nextafterf+ failed");
27 ++result;
29 if (fetestexcept (FE_OVERFLOW) == 0)
31 puts ("nextafterf+ did not overflow");
32 ++result;
34 feclearexcept (FE_ALL_EXCEPT);
35 if (nextafterf (-m, -i) != -i)
37 puts ("nextafterf- failed");
38 ++result;
40 if (fetestexcept (FE_OVERFLOW) == 0)
42 puts ("nextafterf- did not overflow");
43 ++result;
46 i = 0;
47 m = FLT_MIN;
48 feclearexcept (FE_ALL_EXCEPT);
49 i = nextafterf (m, i);
50 if (i < 0 || i >= FLT_MIN)
52 puts ("nextafterf+ failed");
53 ++result;
55 if (fetestexcept (FE_UNDERFLOW) == 0)
57 puts ("nextafterf+ did not underflow");
58 ++result;
60 i = 0;
61 feclearexcept (FE_ALL_EXCEPT);
62 i = nextafterf (-m, -i);
63 if (i > 0 || i <= -FLT_MIN)
65 puts ("nextafterf- failed");
66 ++result;
68 if (fetestexcept (FE_UNDERFLOW) == 0)
70 puts ("nextafterf- did not underflow");
71 ++result;
73 i = -INFINITY;
74 feclearexcept (FE_ALL_EXCEPT);
75 m = nextafterf (zero, inf);
76 if (m < 0.0 || m >= FLT_MIN)
78 puts ("nextafterf+ failed");
79 ++result;
81 if (fetestexcept (FE_UNDERFLOW) == 0)
83 puts ("nextafterf+ did not underflow");
84 ++result;
86 feclearexcept (FE_ALL_EXCEPT);
87 if (nextafterf (m, i) != 0.0)
89 puts ("nextafterf+ failed");
90 ++result;
92 if (fetestexcept (FE_UNDERFLOW) == 0)
94 puts ("nextafterf+ did not underflow");
95 ++result;
97 feclearexcept (FE_ALL_EXCEPT);
98 m = nextafterf (copysignf (zero, -1.0), -inf);
99 if (m > 0.0 || m <= -FLT_MIN)
101 puts ("nextafterf- failed");
102 ++result;
104 if (fetestexcept (FE_UNDERFLOW) == 0)
106 puts ("nextafterf- did not underflow");
107 ++result;
109 feclearexcept (FE_ALL_EXCEPT);
110 if (nextafterf (m, -i) != 0.0)
112 puts ("nextafterf- failed");
113 ++result;
115 if (fetestexcept (FE_UNDERFLOW) == 0)
117 puts ("nextafterf- did not underflow");
118 ++result;
121 double di = INFINITY;
122 double dm = DBL_MAX;
123 feclearexcept (FE_ALL_EXCEPT);
124 if (nextafter (dm, di) != di)
126 puts ("nextafter+ failed");
127 ++result;
129 if (fetestexcept (FE_OVERFLOW) == 0)
131 puts ("nextafter+ did not overflow");
132 ++result;
134 feclearexcept (FE_ALL_EXCEPT);
135 if (nextafter (-dm, -di) != -di)
137 puts ("nextafter failed");
138 ++result;
140 if (fetestexcept (FE_OVERFLOW) == 0)
142 puts ("nextafter- did not overflow");
143 ++result;
146 di = 0;
147 dm = DBL_MIN;
148 feclearexcept (FE_ALL_EXCEPT);
149 di = nextafter (dm, di);
150 if (di < 0 || di >= DBL_MIN)
152 puts ("nextafter+ failed");
153 ++result;
155 if (fetestexcept (FE_UNDERFLOW) == 0)
157 puts ("nextafter+ did not underflow");
158 ++result;
160 di = 0;
161 feclearexcept (FE_ALL_EXCEPT);
162 di = nextafter (-dm, -di);
163 if (di > 0 || di <= -DBL_MIN)
165 puts ("nextafter- failed");
166 ++result;
168 if (fetestexcept (FE_UNDERFLOW) == 0)
170 puts ("nextafter- did not underflow");
171 ++result;
173 di = -INFINITY;
174 feclearexcept (FE_ALL_EXCEPT);
175 dm = nextafter (zero, inf);
176 if (dm < 0.0 || dm >= DBL_MIN)
178 puts ("nextafter+ failed");
179 ++result;
181 if (fetestexcept (FE_UNDERFLOW) == 0)
183 puts ("nextafter+ did not underflow");
184 ++result;
186 feclearexcept (FE_ALL_EXCEPT);
187 if (nextafter (dm, di) != 0.0)
189 puts ("nextafter+ failed");
190 ++result;
192 if (fetestexcept (FE_UNDERFLOW) == 0)
194 puts ("nextafter+ did not underflow");
195 ++result;
197 feclearexcept (FE_ALL_EXCEPT);
198 dm = nextafter (copysign (zero, -1.0), -inf);
199 if (dm > 0.0 || dm <= -DBL_MIN)
201 puts ("nextafter- failed");
202 ++result;
204 if (fetestexcept (FE_UNDERFLOW) == 0)
206 puts ("nextafter- did not underflow");
207 ++result;
209 feclearexcept (FE_ALL_EXCEPT);
210 if (nextafter (dm, -di) != 0.0)
212 puts ("nextafter- failed");
213 ++result;
215 if (fetestexcept (FE_UNDERFLOW) == 0)
217 puts ("nextafter- did not underflow");
218 ++result;
221 #ifndef NO_LONG_DOUBLE
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 (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 (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 (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 (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 (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 (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 (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 (fetestexcept (FE_UNDERFLOW) == 0)
318 puts ("nextafterl- did not underflow");
319 ++result;
321 #endif
323 return result;