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
22 long double tl
= (long double) FLT_MAX
+ 0x1.0p128L
;
25 feclearexcept (FE_ALL_EXCEPT
);
26 if (nexttowardf (m
, tl
) != fi
)
28 puts ("nexttowardf+ failed");
31 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW
) == 0)
33 puts ("nexttowardf+ did not overflow");
36 feclearexcept (FE_ALL_EXCEPT
);
37 if (nexttowardf (-m
, -tl
) != -fi
)
39 puts ("nexttowardf- failed");
42 if (EXCEPTION_TESTS (float) && fetestexcept (FE_OVERFLOW
) == 0)
44 puts ("nexttowardf- did not overflow");
50 feclearexcept (FE_ALL_EXCEPT
);
51 fi
= nexttowardf (m
, fi
);
52 if (fi
< 0 || fi
>= FLT_MIN
)
54 puts ("nexttowardf+ failed");
57 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
59 puts ("nexttowardf+ did not underflow");
63 feclearexcept (FE_ALL_EXCEPT
);
64 fi
= nexttowardf (-m
, -fi
);
65 if (fi
> 0 || fi
<= -FLT_MIN
)
67 puts ("nexttowardf- failed");
70 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
72 puts ("nexttowardf- did not underflow");
76 feclearexcept (FE_ALL_EXCEPT
);
77 m
= nexttowardf (zero
, inf
);
78 if (m
< 0.0 || m
>= FLT_MIN
)
80 puts ("nexttowardf+ failed");
83 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
85 puts ("nexttowardf+ did not underflow");
88 feclearexcept (FE_ALL_EXCEPT
);
89 if (nexttowardf (m
, fi
) != 0.0)
91 puts ("nexttowardf+ failed");
94 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
96 puts ("nexttowardf+ did not underflow");
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");
106 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
108 puts ("nexttowardf- did not underflow");
111 feclearexcept (FE_ALL_EXCEPT
);
112 if (nexttowardf (m
, -fi
) != 0.0)
114 puts ("nexttowardf- failed");
117 if (EXCEPTION_TESTS (float) && fetestexcept (FE_UNDERFLOW
) == 0)
119 puts ("nexttowardf- did not underflow");
123 tl
= (long double) DBL_MAX
+ 1.0e305L
;
124 double di
= INFINITY
;
126 feclearexcept (FE_ALL_EXCEPT
);
127 if (nexttoward (dm
, tl
) != di
)
129 puts ("nexttoward+ failed");
132 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW
) == 0)
134 puts ("nexttoward+ did not overflow");
137 feclearexcept (FE_ALL_EXCEPT
);
138 if (nexttoward (-dm
, -tl
) != -di
)
140 puts ("nexttoward- failed");
143 if (EXCEPTION_TESTS (double) && fetestexcept (FE_OVERFLOW
) == 0)
145 puts ("nexttoward- did not overflow");
151 feclearexcept (FE_ALL_EXCEPT
);
152 di
= nexttoward (dm
, di
);
153 if (di
< 0 || di
>= DBL_MIN
)
155 puts ("nexttoward+ failed");
158 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
160 puts ("nexttoward+ did not underflow");
164 feclearexcept (FE_ALL_EXCEPT
);
165 di
= nexttoward (-dm
, -di
);
166 if (di
> 0 || di
<= -DBL_MIN
)
168 puts ("nexttoward- failed");
171 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
173 puts ("nexttoward- did not underflow");
177 feclearexcept (FE_ALL_EXCEPT
);
178 dm
= nexttoward (zero
, inf
);
179 if (dm
< 0.0 || dm
>= DBL_MIN
)
181 puts ("nexttoward+ failed");
184 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
186 puts ("nexttoward+ did not underflow");
189 feclearexcept (FE_ALL_EXCEPT
);
190 if (nexttoward (dm
, di
) != 0.0)
192 puts ("nexttoward+ failed");
195 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
197 puts ("nexttoward+ did not underflow");
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");
207 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
209 puts ("nexttoward- did not underflow");
212 feclearexcept (FE_ALL_EXCEPT
);
213 if (nexttoward (dm
, -di
) != 0.0)
215 puts ("nexttoward- failed");
218 if (EXCEPTION_TESTS (double) && fetestexcept (FE_UNDERFLOW
) == 0)
220 puts ("nexttoward- did not underflow");
224 #ifndef NO_LONG_DOUBLE
225 long double li
= INFINITY
;
226 long double lm
= LDBL_MAX
;
227 feclearexcept (FE_ALL_EXCEPT
);
228 if (nexttowardl (lm
, li
) != li
)
230 puts ("nexttowardl+ failed");
233 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW
) == 0)
235 puts ("nexttowardl+ did not overflow");
238 feclearexcept (FE_ALL_EXCEPT
);
239 if (nexttowardl (-lm
, -li
) != -li
)
241 puts ("nexttowardl failed");
244 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_OVERFLOW
) == 0)
246 puts ("nexttowardl- did not overflow");
252 feclearexcept (FE_ALL_EXCEPT
);
253 li
= nexttowardl (lm
, li
);
254 if (li
< 0 || li
>= LDBL_MIN
)
256 puts ("nexttowardl+ failed");
259 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
261 puts ("nexttowardl+ did not underflow");
265 feclearexcept (FE_ALL_EXCEPT
);
266 li
= nexttowardl (-lm
, -li
);
267 if (li
> 0 || li
<= -LDBL_MIN
)
269 puts ("nexttowardl- failed");
272 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
274 puts ("nexttowardl- did not underflow");
278 feclearexcept (FE_ALL_EXCEPT
);
279 lm
= nexttowardl (zero
, inf
);
280 if (lm
< 0.0 || lm
>= LDBL_MIN
)
282 puts ("nexttowardl+ failed");
285 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
287 puts ("nexttowardl+ did not underflow");
290 feclearexcept (FE_ALL_EXCEPT
);
291 if (nexttowardl (lm
, li
) != 0.0)
293 puts ("nexttowardl+ failed");
296 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
298 puts ("nexttowardl+ did not underflow");
301 feclearexcept (FE_ALL_EXCEPT
);
302 lm
= nexttowardl (copysign (zero
, -1.0), -inf
);
303 if (lm
> 0.0 || lm
<= -LDBL_MIN
)
305 puts ("nexttowardl- failed");
308 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
310 puts ("nexttowardl- did not underflow");
313 feclearexcept (FE_ALL_EXCEPT
);
314 if (nexttowardl (lm
, -li
) != 0.0)
316 puts ("nexttowardl- failed");
319 if (EXCEPTION_TESTS (long double) && fetestexcept (FE_UNDERFLOW
) == 0)
321 puts ("nexttowardl- did not underflow");