Move _dl_important_hwcaps to dl-hwcaps.c
[platform/upstream/glibc.git] / math / bug-nexttoward.c
1 #include <fenv.h>
2 #include <math.h>
3 #include <float.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6
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
12
13 float zero = 0.0;
14 float inf = INFINITY;
15
16 int
17 main (void)
18 {
19   int result = 0;
20
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)
26     {
27       puts ("nexttowardf+ failed");
28       ++result;
29     }
30   if (fetestexcept (FE_OVERFLOW) == 0)
31     {
32       puts ("nexttowardf+ did not overflow");
33       ++result;
34     }
35   feclearexcept (FE_ALL_EXCEPT);
36   if (nexttowardf (-m, -tl) != -fi)
37     {
38       puts ("nexttowardf- failed");
39       ++result;
40     }
41   if (fetestexcept (FE_OVERFLOW) == 0)
42     {
43       puts ("nexttowardf- did not overflow");
44       ++result;
45     }
46
47   fi = 0;
48   m = FLT_MIN;
49   feclearexcept (FE_ALL_EXCEPT);
50   fi = nexttowardf (m, fi);
51   if (fi < 0 || fi >= FLT_MIN)
52     {
53       puts ("nexttowardf+ failed");
54       ++result;
55     }
56   if (fetestexcept (FE_UNDERFLOW) == 0)
57     {
58       puts ("nexttowardf+ did not underflow");
59       ++result;
60     }
61   fi = 0;
62   feclearexcept (FE_ALL_EXCEPT);
63   fi = nexttowardf (-m, -fi);
64   if (fi > 0 || fi <= -FLT_MIN)
65     {
66       puts ("nexttowardf- failed");
67       ++result;
68     }
69   if (fetestexcept (FE_UNDERFLOW) == 0)
70     {
71       puts ("nexttowardf- did not underflow");
72       ++result;
73     }
74   fi = -INFINITY;
75   feclearexcept (FE_ALL_EXCEPT);
76   m = nexttowardf (zero, inf);
77   if (m < 0.0 || m >= FLT_MIN)
78     {
79       puts ("nexttowardf+ failed");
80       ++result;
81     }
82   if (fetestexcept (FE_UNDERFLOW) == 0)
83     {
84       puts ("nexttowardf+ did not underflow");
85       ++result;
86     }
87   feclearexcept (FE_ALL_EXCEPT);
88   if (nexttowardf (m, fi) != 0.0)
89     {
90       puts ("nexttowardf+ failed");
91       ++result;
92     }
93   if (fetestexcept (FE_UNDERFLOW) == 0)
94     {
95       puts ("nexttowardf+ did not underflow");
96       ++result;
97     }
98   feclearexcept (FE_ALL_EXCEPT);
99   m = nexttowardf (copysignf (zero, -1.0), -inf);
100   if (m > 0.0 || m <= -FLT_MIN)
101     {
102       puts ("nexttowardf- failed");
103       ++result;
104     }
105   if (fetestexcept (FE_UNDERFLOW) == 0)
106     {
107       puts ("nexttowardf- did not underflow");
108       ++result;
109     }
110   feclearexcept (FE_ALL_EXCEPT);
111   if (nexttowardf (m, -fi) != 0.0)
112     {
113       puts ("nexttowardf- failed");
114       ++result;
115     }
116   if (fetestexcept (FE_UNDERFLOW) == 0)
117     {
118       puts ("nexttowardf- did not underflow");
119       ++result;
120     }
121
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)
127     {
128       puts ("nexttoward+ failed");
129       ++result;
130     }
131   if (fetestexcept (FE_OVERFLOW) == 0)
132     {
133       puts ("nexttoward+ did not overflow");
134       ++result;
135     }
136   feclearexcept (FE_ALL_EXCEPT);
137   if (nexttoward (-dm, -tl) != -di)
138     {
139       puts ("nexttoward- failed");
140       ++result;
141     }
142   if (fetestexcept (FE_OVERFLOW) == 0)
143     {
144       puts ("nexttoward- did not overflow");
145       ++result;
146     }
147
148   di = 0;
149   dm = DBL_MIN;
150   feclearexcept (FE_ALL_EXCEPT);
151   di = nexttoward (dm, di);
152   if (di < 0 || di >= DBL_MIN)
153     {
154       puts ("nexttoward+ failed");
155       ++result;
156     }
157   if (fetestexcept (FE_UNDERFLOW) == 0)
158     {
159       puts ("nexttoward+ did not underflow");
160       ++result;
161     }
162   di = 0;
163   feclearexcept (FE_ALL_EXCEPT);
164   di = nexttoward (-dm, -di);
165   if (di > 0 || di <= -DBL_MIN)
166     {
167       puts ("nexttoward- failed");
168       ++result;
169     }
170   if (fetestexcept (FE_UNDERFLOW) == 0)
171     {
172       puts ("nexttoward- did not underflow");
173       ++result;
174     }
175   di = -INFINITY;
176   feclearexcept (FE_ALL_EXCEPT);
177   dm = nexttoward (zero, inf);
178   if (dm < 0.0 || dm >= DBL_MIN)
179     {
180       puts ("nexttoward+ failed");
181       ++result;
182     }
183   if (fetestexcept (FE_UNDERFLOW) == 0)
184     {
185       puts ("nexttoward+ did not underflow");
186       ++result;
187     }
188   feclearexcept (FE_ALL_EXCEPT);
189   if (nexttoward (dm, di) != 0.0)
190     {
191       puts ("nexttoward+ failed");
192       ++result;
193     }
194   if (fetestexcept (FE_UNDERFLOW) == 0)
195     {
196       puts ("nexttoward+ did not underflow");
197       ++result;
198     }
199   feclearexcept (FE_ALL_EXCEPT);
200   dm = nexttoward (copysign (zero, -1.0), -inf);
201   if (dm > 0.0 || dm <= -DBL_MIN)
202     {
203       puts ("nexttoward- failed");
204       ++result;
205     }
206   if (fetestexcept (FE_UNDERFLOW) == 0)
207     {
208       puts ("nexttoward- did not underflow");
209       ++result;
210     }
211   feclearexcept (FE_ALL_EXCEPT);
212   if (nexttoward (dm, -di) != 0.0)
213     {
214       puts ("nexttoward- failed");
215       ++result;
216     }
217   if (fetestexcept (FE_UNDERFLOW) == 0)
218     {
219       puts ("nexttoward- did not underflow");
220       ++result;
221     }
222
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)
228     {
229       puts ("nexttowardl+ failed");
230       ++result;
231     }
232   if (fetestexcept (FE_OVERFLOW) == 0)
233     {
234       puts ("nexttowardl+ did not overflow");
235       ++result;
236     }
237   feclearexcept (FE_ALL_EXCEPT);
238   if (nexttowardl (-lm, -li) != -li)
239     {
240       puts ("nexttowardl failed");
241       ++result;
242     }
243   if (fetestexcept (FE_OVERFLOW) == 0)
244     {
245       puts ("nexttowardl- did not overflow");
246       ++result;
247     }
248
249   li = 0;
250   lm = LDBL_MIN;
251   feclearexcept (FE_ALL_EXCEPT);
252   li = nexttowardl (lm, li);
253   if (li < 0 || li >= LDBL_MIN)
254     {
255       puts ("nexttowardl+ failed");
256       ++result;
257     }
258   if (fetestexcept (FE_UNDERFLOW) == 0)
259     {
260       puts ("nexttowardl+ did not underflow");
261       ++result;
262     }
263   li = 0;
264   feclearexcept (FE_ALL_EXCEPT);
265   li = nexttowardl (-lm, -li);
266   if (li > 0 || li <= -LDBL_MIN)
267     {
268       puts ("nexttowardl- failed");
269       ++result;
270     }
271   if (fetestexcept (FE_UNDERFLOW) == 0)
272     {
273       puts ("nexttowardl- did not underflow");
274       ++result;
275     }
276   li = -INFINITY;
277   feclearexcept (FE_ALL_EXCEPT);
278   lm = nexttowardl (zero, inf);
279   if (lm < 0.0 || lm >= LDBL_MIN)
280     {
281       puts ("nexttowardl+ failed");
282       ++result;
283     }
284   if (fetestexcept (FE_UNDERFLOW) == 0)
285     {
286       puts ("nexttowardl+ did not underflow");
287       ++result;
288     }
289   feclearexcept (FE_ALL_EXCEPT);
290   if (nexttowardl (lm, li) != 0.0)
291     {
292       puts ("nexttowardl+ failed");
293       ++result;
294     }
295   if (fetestexcept (FE_UNDERFLOW) == 0)
296     {
297       puts ("nexttowardl+ did not underflow");
298       ++result;
299     }
300   feclearexcept (FE_ALL_EXCEPT);
301   lm = nexttowardl (copysign (zero, -1.0), -inf);
302   if (lm > 0.0 || lm <= -LDBL_MIN)
303     {
304       puts ("nexttowardl- failed");
305       ++result;
306     }
307   if (fetestexcept (FE_UNDERFLOW) == 0)
308     {
309       puts ("nexttowardl- did not underflow");
310       ++result;
311     }
312   feclearexcept (FE_ALL_EXCEPT);
313   if (nexttowardl (lm, -li) != 0.0)
314     {
315       puts ("nexttowardl- failed");
316       ++result;
317     }
318   if (fetestexcept (FE_UNDERFLOW) == 0)
319     {
320       puts ("nexttowardl- did not underflow");
321       ++result;
322     }
323 #endif
324
325   return result;
326 }