2.9
[glibc/nacl-glibc.git] / math / bug-nexttoward.c
blobff57e5e3f519a9ee6d12acf3ce441387c3e3d72a
1 #include <fenv.h>
2 #include <math.h>
3 #include <float.h>
4 #include <stdlib.h>
5 #include <stdio.h>
7 float zero = 0.0;
8 float inf = INFINITY;
10 int
11 main (void)
13 int result = 0;
15 long double tl = (long double) FLT_MAX + 0x1.0p128L;
16 float fi = INFINITY;
17 float m = FLT_MAX;
18 feclearexcept (FE_ALL_EXCEPT);
19 if (nexttowardf (m, tl) != fi)
21 puts ("nexttowardf+ failed");
22 ++result;
24 if (fetestexcept (FE_OVERFLOW) == 0)
26 puts ("nexttowardf+ did not overflow");
27 ++result;
29 feclearexcept (FE_ALL_EXCEPT);
30 if (nexttowardf (-m, -tl) != -fi)
32 puts ("nexttowardf- failed");
33 ++result;
35 if (fetestexcept (FE_OVERFLOW) == 0)
37 puts ("nexttowardf- did not overflow");
38 ++result;
41 fi = 0;
42 m = FLT_MIN;
43 feclearexcept (FE_ALL_EXCEPT);
44 fi = nexttowardf (m, fi);
45 if (fi < 0 || fi >= FLT_MIN)
47 puts ("nexttowardf+ failed");
48 ++result;
50 if (fetestexcept (FE_UNDERFLOW) == 0)
52 puts ("nexttowardf+ did not underflow");
53 ++result;
55 fi = 0;
56 feclearexcept (FE_ALL_EXCEPT);
57 fi = nexttowardf (-m, -fi);
58 if (fi > 0 || fi <= -FLT_MIN)
60 puts ("nexttowardf- failed");
61 ++result;
63 if (fetestexcept (FE_UNDERFLOW) == 0)
65 puts ("nexttowardf- did not underflow");
66 ++result;
68 fi = -INFINITY;
69 feclearexcept (FE_ALL_EXCEPT);
70 m = nexttowardf (zero, inf);
71 if (m < 0.0 || m >= FLT_MIN)
73 puts ("nexttowardf+ failed");
74 ++result;
76 if (fetestexcept (FE_UNDERFLOW) == 0)
78 puts ("nexttowardf+ did not underflow");
79 ++result;
81 feclearexcept (FE_ALL_EXCEPT);
82 if (nexttowardf (m, fi) != 0.0)
84 puts ("nexttowardf+ failed");
85 ++result;
87 if (fetestexcept (FE_UNDERFLOW) == 0)
89 puts ("nexttowardf+ did not underflow");
90 ++result;
92 feclearexcept (FE_ALL_EXCEPT);
93 m = nexttowardf (copysignf (zero, -1.0), -inf);
94 if (m > 0.0 || m <= -FLT_MIN)
96 puts ("nexttowardf- failed");
97 ++result;
99 if (fetestexcept (FE_UNDERFLOW) == 0)
101 puts ("nexttowardf- did not underflow");
102 ++result;
104 feclearexcept (FE_ALL_EXCEPT);
105 if (nexttowardf (m, -fi) != 0.0)
107 puts ("nexttowardf- failed");
108 ++result;
110 if (fetestexcept (FE_UNDERFLOW) == 0)
112 puts ("nexttowardf- did not underflow");
113 ++result;
116 tl = (long double) DBL_MAX + 1.0e305L;
117 double di = INFINITY;
118 double dm = DBL_MAX;
119 feclearexcept (FE_ALL_EXCEPT);
120 if (nexttoward (dm, tl) != di)
122 puts ("nexttoward+ failed");
123 ++result;
125 if (fetestexcept (FE_OVERFLOW) == 0)
127 puts ("nexttoward+ did not overflow");
128 ++result;
130 feclearexcept (FE_ALL_EXCEPT);
131 if (nexttoward (-dm, -tl) != -di)
133 puts ("nexttoward- failed");
134 ++result;
136 if (fetestexcept (FE_OVERFLOW) == 0)
138 puts ("nexttoward- did not overflow");
139 ++result;
142 di = 0;
143 dm = DBL_MIN;
144 feclearexcept (FE_ALL_EXCEPT);
145 di = nexttoward (dm, di);
146 if (di < 0 || di >= DBL_MIN)
148 puts ("nexttoward+ failed");
149 ++result;
151 if (fetestexcept (FE_UNDERFLOW) == 0)
153 puts ("nexttoward+ did not underflow");
154 ++result;
156 di = 0;
157 feclearexcept (FE_ALL_EXCEPT);
158 di = nexttoward (-dm, -di);
159 if (di > 0 || di <= -DBL_MIN)
161 puts ("nexttoward- failed");
162 ++result;
164 if (fetestexcept (FE_UNDERFLOW) == 0)
166 puts ("nexttoward- did not underflow");
167 ++result;
169 di = -INFINITY;
170 feclearexcept (FE_ALL_EXCEPT);
171 dm = nexttoward (zero, inf);
172 if (dm < 0.0 || dm >= DBL_MIN)
174 puts ("nexttoward+ failed");
175 ++result;
177 if (fetestexcept (FE_UNDERFLOW) == 0)
179 puts ("nexttoward+ did not underflow");
180 ++result;
182 feclearexcept (FE_ALL_EXCEPT);
183 if (nexttoward (dm, di) != 0.0)
185 puts ("nexttoward+ failed");
186 ++result;
188 if (fetestexcept (FE_UNDERFLOW) == 0)
190 puts ("nexttoward+ did not underflow");
191 ++result;
193 feclearexcept (FE_ALL_EXCEPT);
194 dm = nexttoward (copysign (zero, -1.0), -inf);
195 if (dm > 0.0 || dm <= -DBL_MIN)
197 puts ("nexttoward- failed");
198 ++result;
200 if (fetestexcept (FE_UNDERFLOW) == 0)
202 puts ("nexttoward- did not underflow");
203 ++result;
205 feclearexcept (FE_ALL_EXCEPT);
206 if (nexttoward (dm, -di) != 0.0)
208 puts ("nexttoward- failed");
209 ++result;
211 if (fetestexcept (FE_UNDERFLOW) == 0)
213 puts ("nexttoward- did not underflow");
214 ++result;
217 #ifndef NO_LONG_DOUBLE
218 long double li = INFINITY;
219 long double lm = LDBL_MAX;
220 feclearexcept (FE_ALL_EXCEPT);
221 if (nexttowardl (lm, li) != li)
223 puts ("nexttowardl+ failed");
224 ++result;
226 if (fetestexcept (FE_OVERFLOW) == 0)
228 puts ("nexttowardl+ did not overflow");
229 ++result;
231 feclearexcept (FE_ALL_EXCEPT);
232 if (nexttowardl (-lm, -li) != -li)
234 puts ("nexttowardl failed");
235 ++result;
237 if (fetestexcept (FE_OVERFLOW) == 0)
239 puts ("nexttowardl- did not overflow");
240 ++result;
243 li = 0;
244 lm = LDBL_MIN;
245 feclearexcept (FE_ALL_EXCEPT);
246 li = nexttowardl (lm, li);
247 if (li < 0 || li >= LDBL_MIN)
249 puts ("nexttowardl+ failed");
250 ++result;
252 if (fetestexcept (FE_UNDERFLOW) == 0)
254 puts ("nexttowardl+ did not underflow");
255 ++result;
257 li = 0;
258 feclearexcept (FE_ALL_EXCEPT);
259 li = nexttowardl (-lm, -li);
260 if (li > 0 || li <= -LDBL_MIN)
262 puts ("nexttowardl- failed");
263 ++result;
265 if (fetestexcept (FE_UNDERFLOW) == 0)
267 puts ("nexttowardl- did not underflow");
268 ++result;
270 li = -INFINITY;
271 feclearexcept (FE_ALL_EXCEPT);
272 lm = nexttowardl (zero, inf);
273 if (lm < 0.0 || lm >= LDBL_MIN)
275 puts ("nexttowardl+ failed");
276 ++result;
278 if (fetestexcept (FE_UNDERFLOW) == 0)
280 puts ("nexttowardl+ did not underflow");
281 ++result;
283 feclearexcept (FE_ALL_EXCEPT);
284 if (nexttowardl (lm, li) != 0.0)
286 puts ("nexttowardl+ failed");
287 ++result;
289 if (fetestexcept (FE_UNDERFLOW) == 0)
291 puts ("nexttowardl+ did not underflow");
292 ++result;
294 feclearexcept (FE_ALL_EXCEPT);
295 lm = nexttowardl (copysign (zero, -1.0), -inf);
296 if (lm > 0.0 || lm <= -LDBL_MIN)
298 puts ("nexttowardl- failed");
299 ++result;
301 if (fetestexcept (FE_UNDERFLOW) == 0)
303 puts ("nexttowardl- did not underflow");
304 ++result;
306 feclearexcept (FE_ALL_EXCEPT);
307 if (nexttowardl (lm, -li) != 0.0)
309 puts ("nexttowardl- failed");
310 ++result;
312 if (fetestexcept (FE_UNDERFLOW) == 0)
314 puts ("nexttowardl- did not underflow");
315 ++result;
317 #endif
319 return result;