Add NT_ARM_PAC_ENABLED_KEYS to elf.h
[glibc.git] / math / bug-nexttoward.c
blobfc57e50d317fe6490070883d94699605435a4c32
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 long double tl = (long double) FLT_MAX + 0x1.0p128L;
23 float fi = INFINITY;
24 float m = FLT_MAX;
25 feclearexcept (FE_ALL_EXCEPT);
26 if (nexttowardf (m, tl) != fi)
28 puts ("nexttowardf+ failed");
29 ++result;
31 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW) == 0)
33 puts ("nexttowardf+ did not overflow");
34 ++result;
36 feclearexcept (FE_ALL_EXCEPT);
37 if (nexttowardf (-m, -tl) != -fi)
39 puts ("nexttowardf- failed");
40 ++result;
42 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW) == 0)
44 puts ("nexttowardf- did not overflow");
45 ++result;
48 fi = 0;
49 m = FLT_MIN;
50 feclearexcept (FE_ALL_EXCEPT);
51 fi = nexttowardf (m, fi);
52 if (fi < 0 || fi >= FLT_MIN)
54 puts ("nexttowardf+ failed");
55 ++result;
57 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
59 puts ("nexttowardf+ did not underflow");
60 ++result;
62 fi = 0;
63 feclearexcept (FE_ALL_EXCEPT);
64 fi = nexttowardf (-m, -fi);
65 if (fi > 0 || fi <= -FLT_MIN)
67 puts ("nexttowardf- failed");
68 ++result;
70 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
72 puts ("nexttowardf- did not underflow");
73 ++result;
75 fi = -INFINITY;
76 feclearexcept (FE_ALL_EXCEPT);
77 m = nexttowardf (zero, inf);
78 if (m < 0.0 || m >= FLT_MIN)
80 puts ("nexttowardf+ failed");
81 ++result;
83 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
85 puts ("nexttowardf+ did not underflow");
86 ++result;
88 feclearexcept (FE_ALL_EXCEPT);
89 if (nexttowardf (m, fi) != 0.0)
91 puts ("nexttowardf+ failed");
92 ++result;
94 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
96 puts ("nexttowardf+ did not underflow");
97 ++result;
99 feclearexcept (FE_ALL_EXCEPT);
100 m = nexttowardf (copysignf (zero, -1.0), -inf);
101 if (m > 0.0 || m <= -FLT_MIN)
103 puts ("nexttowardf- failed");
104 ++result;
106 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
108 puts ("nexttowardf- did not underflow");
109 ++result;
111 feclearexcept (FE_ALL_EXCEPT);
112 if (nexttowardf (m, -fi) != 0.0)
114 puts ("nexttowardf- failed");
115 ++result;
117 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW) == 0)
119 puts ("nexttowardf- did not underflow");
120 ++result;
123 tl = (long double) DBL_MAX + 1.0e305L;
124 double di = INFINITY;
125 double dm = DBL_MAX;
126 feclearexcept (FE_ALL_EXCEPT);
127 if (nexttoward (dm, tl) != di)
129 puts ("nexttoward+ failed");
130 ++result;
132 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW) == 0)
134 puts ("nexttoward+ did not overflow");
135 ++result;
137 feclearexcept (FE_ALL_EXCEPT);
138 if (nexttoward (-dm, -tl) != -di)
140 puts ("nexttoward- failed");
141 ++result;
143 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW) == 0)
145 puts ("nexttoward- did not overflow");
146 ++result;
149 di = 0;
150 dm = DBL_MIN;
151 feclearexcept (FE_ALL_EXCEPT);
152 di = nexttoward (dm, di);
153 if (di < 0 || di >= DBL_MIN)
155 puts ("nexttoward+ failed");
156 ++result;
158 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
160 puts ("nexttoward+ did not underflow");
161 ++result;
163 di = 0;
164 feclearexcept (FE_ALL_EXCEPT);
165 di = nexttoward (-dm, -di);
166 if (di > 0 || di <= -DBL_MIN)
168 puts ("nexttoward- failed");
169 ++result;
171 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
173 puts ("nexttoward- did not underflow");
174 ++result;
176 di = -INFINITY;
177 feclearexcept (FE_ALL_EXCEPT);
178 dm = nexttoward (zero, inf);
179 if (dm < 0.0 || dm >= DBL_MIN)
181 puts ("nexttoward+ failed");
182 ++result;
184 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
186 puts ("nexttoward+ did not underflow");
187 ++result;
189 feclearexcept (FE_ALL_EXCEPT);
190 if (nexttoward (dm, di) != 0.0)
192 puts ("nexttoward+ failed");
193 ++result;
195 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
197 puts ("nexttoward+ did not underflow");
198 ++result;
200 feclearexcept (FE_ALL_EXCEPT);
201 dm = nexttoward (copysign (zero, -1.0), -inf);
202 if (dm > 0.0 || dm <= -DBL_MIN)
204 puts ("nexttoward- failed");
205 ++result;
207 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
209 puts ("nexttoward- did not underflow");
210 ++result;
212 feclearexcept (FE_ALL_EXCEPT);
213 if (nexttoward (dm, -di) != 0.0)
215 puts ("nexttoward- failed");
216 ++result;
218 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW) == 0)
220 puts ("nexttoward- did not underflow");
221 ++result;
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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && 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 (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW) == 0)
320 puts ("nexttowardl- did not underflow");
321 ++result;
324 return result;