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
24 feclearexcept (FE_ALL_EXCEPT
);
25 if (nextafterf (m
, i
) != i
)
27 puts ("nextafterf+ failed");
30 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW
) == 0)
32 puts ("nextafterf+ did not overflow");
35 feclearexcept (FE_ALL_EXCEPT
);
36 if (nextafterf (-m
, -i
) != -i
)
38 puts ("nextafterf- failed");
41 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW
) == 0)
43 puts ("nextafterf- did not overflow");
49 feclearexcept (FE_ALL_EXCEPT
);
50 i
= nextafterf (m
, i
);
51 if (i
< 0 || i
>= FLT_MIN
)
53 puts ("nextafterf+ failed");
56 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
58 puts ("nextafterf+ did not underflow");
62 feclearexcept (FE_ALL_EXCEPT
);
63 i
= nextafterf (-m
, -i
);
64 if (i
> 0 || i
<= -FLT_MIN
)
66 puts ("nextafterf- failed");
69 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
71 puts ("nextafterf- did not underflow");
75 feclearexcept (FE_ALL_EXCEPT
);
76 m
= nextafterf (zero
, inf
);
77 if (m
< 0.0 || m
>= FLT_MIN
)
79 puts ("nextafterf+ failed");
82 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
84 puts ("nextafterf+ did not underflow");
87 feclearexcept (FE_ALL_EXCEPT
);
88 if (nextafterf (m
, i
) != 0.0)
90 puts ("nextafterf+ failed");
93 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
95 puts ("nextafterf+ did not underflow");
98 feclearexcept (FE_ALL_EXCEPT
);
99 m
= nextafterf (copysignf (zero
, -1.0), -inf
);
100 if (m
> 0.0 || m
<= -FLT_MIN
)
102 puts ("nextafterf- failed");
105 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
107 puts ("nextafterf- did not underflow");
110 feclearexcept (FE_ALL_EXCEPT
);
111 if (nextafterf (m
, -i
) != 0.0)
113 puts ("nextafterf- failed");
116 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
118 puts ("nextafterf- did not underflow");
122 double di
= INFINITY
;
124 feclearexcept (FE_ALL_EXCEPT
);
125 if (nextafter (dm
, di
) != di
)
127 puts ("nextafter+ failed");
130 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW
) == 0)
132 puts ("nextafter+ did not overflow");
135 feclearexcept (FE_ALL_EXCEPT
);
136 if (nextafter (-dm
, -di
) != -di
)
138 puts ("nextafter failed");
141 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW
) == 0)
143 puts ("nextafter- did not overflow");
149 feclearexcept (FE_ALL_EXCEPT
);
150 di
= nextafter (dm
, di
);
151 if (di
< 0 || di
>= DBL_MIN
)
153 puts ("nextafter+ failed");
156 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
158 puts ("nextafter+ did not underflow");
162 feclearexcept (FE_ALL_EXCEPT
);
163 di
= nextafter (-dm
, -di
);
164 if (di
> 0 || di
<= -DBL_MIN
)
166 puts ("nextafter- failed");
169 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
171 puts ("nextafter- did not underflow");
175 feclearexcept (FE_ALL_EXCEPT
);
176 dm
= nextafter (zero
, inf
);
177 if (dm
< 0.0 || dm
>= DBL_MIN
)
179 puts ("nextafter+ failed");
182 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
184 puts ("nextafter+ did not underflow");
187 feclearexcept (FE_ALL_EXCEPT
);
188 if (nextafter (dm
, di
) != 0.0)
190 puts ("nextafter+ failed");
193 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
195 puts ("nextafter+ did not underflow");
198 feclearexcept (FE_ALL_EXCEPT
);
199 dm
= nextafter (copysign (zero
, -1.0), -inf
);
200 if (dm
> 0.0 || dm
<= -DBL_MIN
)
202 puts ("nextafter- failed");
205 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
207 puts ("nextafter- did not underflow");
210 feclearexcept (FE_ALL_EXCEPT
);
211 if (nextafter (dm
, -di
) != 0.0)
213 puts ("nextafter- failed");
216 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
218 puts ("nextafter- did not underflow");
222 #ifndef NO_LONG_DOUBLE
223 long double li
= INFINITY
;
224 long double lm
= LDBL_MAX
;
225 feclearexcept (FE_ALL_EXCEPT
);
226 if (nextafterl (lm
, li
) != li
)
228 puts ("nextafterl+ failed");
231 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW
) == 0)
233 puts ("nextafterl+ did not overflow");
236 feclearexcept (FE_ALL_EXCEPT
);
237 if (nextafterl (-lm
, -li
) != -li
)
239 puts ("nextafterl failed");
242 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW
) == 0)
244 puts ("nextafterl- did not overflow");
250 feclearexcept (FE_ALL_EXCEPT
);
251 li
= nextafterl (lm
, li
);
252 if (li
< 0 || li
>= LDBL_MIN
)
254 puts ("nextafterl+ failed");
257 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
259 puts ("nextafterl+ did not underflow");
263 feclearexcept (FE_ALL_EXCEPT
);
264 li
= nextafterl (-lm
, -li
);
265 if (li
> 0 || li
<= -LDBL_MIN
)
267 puts ("nextafterl- failed");
270 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
272 puts ("nextafterl- did not underflow");
276 feclearexcept (FE_ALL_EXCEPT
);
277 lm
= nextafterl (zero
, inf
);
278 if (lm
< 0.0 || lm
>= LDBL_MIN
)
280 puts ("nextafterl+ failed");
283 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
285 puts ("nextafterl+ did not underflow");
288 feclearexcept (FE_ALL_EXCEPT
);
289 if (nextafterl (lm
, li
) != 0.0)
291 puts ("nextafterl+ failed");
294 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
296 puts ("nextafterl+ did not underflow");
299 feclearexcept (FE_ALL_EXCEPT
);
300 lm
= nextafterl (copysign (zero
, -1.0), -inf
);
301 if (lm
> 0.0 || lm
<= -LDBL_MIN
)
303 puts ("nextafterl- failed");
306 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
308 puts ("nextafterl- did not underflow");
311 feclearexcept (FE_ALL_EXCEPT
);
312 if (nextafterl (lm
, -li
) != 0.0)
314 puts ("nextafterl- failed");
317 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
319 puts ("nextafterl- did not underflow");