PowerPC: fix libm ABI issue for llroundl
[glibc.git] / math / bug-nexttoward.c
blobcedb7767b6c18879bab466cd794ad4ef07931e18
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 long double tl = (long double) FLT_MAX + 0x1.0p128L;
22 float fi = INFINITY;
23 float m = FLT_MAX;
24 feclearexcept (FE_ALL_EXCEPT);
25 if (nexttowardf (m, tl) != fi)
27 puts ("nexttowardf+ failed");
28 ++result;
30 if (fetestexcept (FE_OVERFLOW) == 0)
32 puts ("nexttowardf+ did not overflow");
33 ++result;
35 feclearexcept (FE_ALL_EXCEPT);
36 if (nexttowardf (-m, -tl) != -fi)
38 puts ("nexttowardf- failed");
39 ++result;
41 if (fetestexcept (FE_OVERFLOW) == 0)
43 puts ("nexttowardf- did not overflow");
44 ++result;
47 fi = 0;
48 m = FLT_MIN;
49 feclearexcept (FE_ALL_EXCEPT);
50 fi = nexttowardf (m, fi);
51 if (fi < 0 || fi >= FLT_MIN)
53 puts ("nexttowardf+ failed");
54 ++result;
56 if (fetestexcept (FE_UNDERFLOW) == 0)
58 puts ("nexttowardf+ did not underflow");
59 ++result;
61 fi = 0;
62 feclearexcept (FE_ALL_EXCEPT);
63 fi = nexttowardf (-m, -fi);
64 if (fi > 0 || fi <= -FLT_MIN)
66 puts ("nexttowardf- failed");
67 ++result;
69 if (fetestexcept (FE_UNDERFLOW) == 0)
71 puts ("nexttowardf- did not underflow");
72 ++result;
74 fi = -INFINITY;
75 feclearexcept (FE_ALL_EXCEPT);
76 m = nexttowardf (zero, inf);
77 if (m < 0.0 || m >= FLT_MIN)
79 puts ("nexttowardf+ failed");
80 ++result;
82 if (fetestexcept (FE_UNDERFLOW) == 0)
84 puts ("nexttowardf+ did not underflow");
85 ++result;
87 feclearexcept (FE_ALL_EXCEPT);
88 if (nexttowardf (m, fi) != 0.0)
90 puts ("nexttowardf+ failed");
91 ++result;
93 if (fetestexcept (FE_UNDERFLOW) == 0)
95 puts ("nexttowardf+ did not underflow");
96 ++result;
98 feclearexcept (FE_ALL_EXCEPT);
99 m = nexttowardf (copysignf (zero, -1.0), -inf);
100 if (m > 0.0 || m <= -FLT_MIN)
102 puts ("nexttowardf- failed");
103 ++result;
105 if (fetestexcept (FE_UNDERFLOW) == 0)
107 puts ("nexttowardf- did not underflow");
108 ++result;
110 feclearexcept (FE_ALL_EXCEPT);
111 if (nexttowardf (m, -fi) != 0.0)
113 puts ("nexttowardf- failed");
114 ++result;
116 if (fetestexcept (FE_UNDERFLOW) == 0)
118 puts ("nexttowardf- did not underflow");
119 ++result;
122 tl = (long double) DBL_MAX + 1.0e305L;
123 double di = INFINITY;
124 double dm = DBL_MAX;
125 feclearexcept (FE_ALL_EXCEPT);
126 if (nexttoward (dm, tl) != di)
128 puts ("nexttoward+ failed");
129 ++result;
131 if (fetestexcept (FE_OVERFLOW) == 0)
133 puts ("nexttoward+ did not overflow");
134 ++result;
136 feclearexcept (FE_ALL_EXCEPT);
137 if (nexttoward (-dm, -tl) != -di)
139 puts ("nexttoward- failed");
140 ++result;
142 if (fetestexcept (FE_OVERFLOW) == 0)
144 puts ("nexttoward- did not overflow");
145 ++result;
148 di = 0;
149 dm = DBL_MIN;
150 feclearexcept (FE_ALL_EXCEPT);
151 di = nexttoward (dm, di);
152 if (di < 0 || di >= DBL_MIN)
154 puts ("nexttoward+ failed");
155 ++result;
157 if (fetestexcept (FE_UNDERFLOW) == 0)
159 puts ("nexttoward+ did not underflow");
160 ++result;
162 di = 0;
163 feclearexcept (FE_ALL_EXCEPT);
164 di = nexttoward (-dm, -di);
165 if (di > 0 || di <= -DBL_MIN)
167 puts ("nexttoward- failed");
168 ++result;
170 if (fetestexcept (FE_UNDERFLOW) == 0)
172 puts ("nexttoward- did not underflow");
173 ++result;
175 di = -INFINITY;
176 feclearexcept (FE_ALL_EXCEPT);
177 dm = nexttoward (zero, inf);
178 if (dm < 0.0 || dm >= DBL_MIN)
180 puts ("nexttoward+ failed");
181 ++result;
183 if (fetestexcept (FE_UNDERFLOW) == 0)
185 puts ("nexttoward+ did not underflow");
186 ++result;
188 feclearexcept (FE_ALL_EXCEPT);
189 if (nexttoward (dm, di) != 0.0)
191 puts ("nexttoward+ failed");
192 ++result;
194 if (fetestexcept (FE_UNDERFLOW) == 0)
196 puts ("nexttoward+ did not underflow");
197 ++result;
199 feclearexcept (FE_ALL_EXCEPT);
200 dm = nexttoward (copysign (zero, -1.0), -inf);
201 if (dm > 0.0 || dm <= -DBL_MIN)
203 puts ("nexttoward- failed");
204 ++result;
206 if (fetestexcept (FE_UNDERFLOW) == 0)
208 puts ("nexttoward- did not underflow");
209 ++result;
211 feclearexcept (FE_ALL_EXCEPT);
212 if (nexttoward (dm, -di) != 0.0)
214 puts ("nexttoward- failed");
215 ++result;
217 if (fetestexcept (FE_UNDERFLOW) == 0)
219 puts ("nexttoward- did not underflow");
220 ++result;
223 #ifndef NO_LONG_DOUBLE
224 long double li = INFINITY;
225 long double lm = LDBL_MAX;
226 feclearexcept (FE_ALL_EXCEPT);
227 if (nexttowardl (lm, li) != li)
229 puts ("nexttowardl+ failed");
230 ++result;
232 if (fetestexcept (FE_OVERFLOW) == 0)
234 puts ("nexttowardl+ did not overflow");
235 ++result;
237 feclearexcept (FE_ALL_EXCEPT);
238 if (nexttowardl (-lm, -li) != -li)
240 puts ("nexttowardl failed");
241 ++result;
243 if (fetestexcept (FE_OVERFLOW) == 0)
245 puts ("nexttowardl- did not overflow");
246 ++result;
249 li = 0;
250 lm = LDBL_MIN;
251 feclearexcept (FE_ALL_EXCEPT);
252 li = nexttowardl (lm, li);
253 if (li < 0 || li >= LDBL_MIN)
255 puts ("nexttowardl+ failed");
256 ++result;
258 if (fetestexcept (FE_UNDERFLOW) == 0)
260 puts ("nexttowardl+ did not underflow");
261 ++result;
263 li = 0;
264 feclearexcept (FE_ALL_EXCEPT);
265 li = nexttowardl (-lm, -li);
266 if (li > 0 || li <= -LDBL_MIN)
268 puts ("nexttowardl- failed");
269 ++result;
271 if (fetestexcept (FE_UNDERFLOW) == 0)
273 puts ("nexttowardl- did not underflow");
274 ++result;
276 li = -INFINITY;
277 feclearexcept (FE_ALL_EXCEPT);
278 lm = nexttowardl (zero, inf);
279 if (lm < 0.0 || lm >= LDBL_MIN)
281 puts ("nexttowardl+ failed");
282 ++result;
284 if (fetestexcept (FE_UNDERFLOW) == 0)
286 puts ("nexttowardl+ did not underflow");
287 ++result;
289 feclearexcept (FE_ALL_EXCEPT);
290 if (nexttowardl (lm, li) != 0.0)
292 puts ("nexttowardl+ failed");
293 ++result;
295 if (fetestexcept (FE_UNDERFLOW) == 0)
297 puts ("nexttowardl+ did not underflow");
298 ++result;
300 feclearexcept (FE_ALL_EXCEPT);
301 lm = nexttowardl (copysign (zero, -1.0), -inf);
302 if (lm > 0.0 || lm <= -LDBL_MIN)
304 puts ("nexttowardl- failed");
305 ++result;
307 if (fetestexcept (FE_UNDERFLOW) == 0)
309 puts ("nexttowardl- did not underflow");
310 ++result;
312 feclearexcept (FE_ALL_EXCEPT);
313 if (nexttowardl (lm, -li) != 0.0)
315 puts ("nexttowardl- failed");
316 ++result;
318 if (fetestexcept (FE_UNDERFLOW) == 0)
320 puts ("nexttowardl- did not underflow");
321 ++result;
323 #endif
325 return result;