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
21 long double tl
= (long double) FLT_MAX
+ 0x1.0p128L
;
24 feclearexcept (FE_ALL_EXCEPT
);
25 if (nexttowardf (m
, tl
) != fi
)
27 puts ("nexttowardf+ failed");
30 if (fetestexcept (FE_OVERFLOW
) == 0)
32 puts ("nexttowardf+ did not overflow");
35 feclearexcept (FE_ALL_EXCEPT
);
36 if (nexttowardf (-m
, -tl
) != -fi
)
38 puts ("nexttowardf- failed");
41 if (fetestexcept (FE_OVERFLOW
) == 0)
43 puts ("nexttowardf- did not overflow");
49 feclearexcept (FE_ALL_EXCEPT
);
50 fi
= nexttowardf (m
, fi
);
51 if (fi
< 0 || fi
>= FLT_MIN
)
53 puts ("nexttowardf+ failed");
56 if (fetestexcept (FE_UNDERFLOW
) == 0)
58 puts ("nexttowardf+ did not underflow");
62 feclearexcept (FE_ALL_EXCEPT
);
63 fi
= nexttowardf (-m
, -fi
);
64 if (fi
> 0 || fi
<= -FLT_MIN
)
66 puts ("nexttowardf- failed");
69 if (fetestexcept (FE_UNDERFLOW
) == 0)
71 puts ("nexttowardf- did not underflow");
75 feclearexcept (FE_ALL_EXCEPT
);
76 m
= nexttowardf (zero
, inf
);
77 if (m
< 0.0 || m
>= FLT_MIN
)
79 puts ("nexttowardf+ failed");
82 if (fetestexcept (FE_UNDERFLOW
) == 0)
84 puts ("nexttowardf+ did not underflow");
87 feclearexcept (FE_ALL_EXCEPT
);
88 if (nexttowardf (m
, fi
) != 0.0)
90 puts ("nexttowardf+ failed");
93 if (fetestexcept (FE_UNDERFLOW
) == 0)
95 puts ("nexttowardf+ did not underflow");
98 feclearexcept (FE_ALL_EXCEPT
);
99 m
= nexttowardf (copysignf (zero
, -1.0), -inf
);
100 if (m
> 0.0 || m
<= -FLT_MIN
)
102 puts ("nexttowardf- failed");
105 if (fetestexcept (FE_UNDERFLOW
) == 0)
107 puts ("nexttowardf- did not underflow");
110 feclearexcept (FE_ALL_EXCEPT
);
111 if (nexttowardf (m
, -fi
) != 0.0)
113 puts ("nexttowardf- failed");
116 if (fetestexcept (FE_UNDERFLOW
) == 0)
118 puts ("nexttowardf- did not underflow");
122 tl
= (long double) DBL_MAX
+ 1.0e305L
;
123 double di
= INFINITY
;
125 feclearexcept (FE_ALL_EXCEPT
);
126 if (nexttoward (dm
, tl
) != di
)
128 puts ("nexttoward+ failed");
131 if (fetestexcept (FE_OVERFLOW
) == 0)
133 puts ("nexttoward+ did not overflow");
136 feclearexcept (FE_ALL_EXCEPT
);
137 if (nexttoward (-dm
, -tl
) != -di
)
139 puts ("nexttoward- failed");
142 if (fetestexcept (FE_OVERFLOW
) == 0)
144 puts ("nexttoward- did not overflow");
150 feclearexcept (FE_ALL_EXCEPT
);
151 di
= nexttoward (dm
, di
);
152 if (di
< 0 || di
>= DBL_MIN
)
154 puts ("nexttoward+ failed");
157 if (fetestexcept (FE_UNDERFLOW
) == 0)
159 puts ("nexttoward+ did not underflow");
163 feclearexcept (FE_ALL_EXCEPT
);
164 di
= nexttoward (-dm
, -di
);
165 if (di
> 0 || di
<= -DBL_MIN
)
167 puts ("nexttoward- failed");
170 if (fetestexcept (FE_UNDERFLOW
) == 0)
172 puts ("nexttoward- did not underflow");
176 feclearexcept (FE_ALL_EXCEPT
);
177 dm
= nexttoward (zero
, inf
);
178 if (dm
< 0.0 || dm
>= DBL_MIN
)
180 puts ("nexttoward+ failed");
183 if (fetestexcept (FE_UNDERFLOW
) == 0)
185 puts ("nexttoward+ did not underflow");
188 feclearexcept (FE_ALL_EXCEPT
);
189 if (nexttoward (dm
, di
) != 0.0)
191 puts ("nexttoward+ failed");
194 if (fetestexcept (FE_UNDERFLOW
) == 0)
196 puts ("nexttoward+ did not underflow");
199 feclearexcept (FE_ALL_EXCEPT
);
200 dm
= nexttoward (copysign (zero
, -1.0), -inf
);
201 if (dm
> 0.0 || dm
<= -DBL_MIN
)
203 puts ("nexttoward- failed");
206 if (fetestexcept (FE_UNDERFLOW
) == 0)
208 puts ("nexttoward- did not underflow");
211 feclearexcept (FE_ALL_EXCEPT
);
212 if (nexttoward (dm
, -di
) != 0.0)
214 puts ("nexttoward- failed");
217 if (fetestexcept (FE_UNDERFLOW
) == 0)
219 puts ("nexttoward- did not underflow");
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
)
229 puts ("nexttowardl+ failed");
232 if (fetestexcept (FE_OVERFLOW
) == 0)
234 puts ("nexttowardl+ did not overflow");
237 feclearexcept (FE_ALL_EXCEPT
);
238 if (nexttowardl (-lm
, -li
) != -li
)
240 puts ("nexttowardl failed");
243 if (fetestexcept (FE_OVERFLOW
) == 0)
245 puts ("nexttowardl- did not overflow");
251 feclearexcept (FE_ALL_EXCEPT
);
252 li
= nexttowardl (lm
, li
);
253 if (li
< 0 || li
>= LDBL_MIN
)
255 puts ("nexttowardl+ failed");
258 if (fetestexcept (FE_UNDERFLOW
) == 0)
260 puts ("nexttowardl+ did not underflow");
264 feclearexcept (FE_ALL_EXCEPT
);
265 li
= nexttowardl (-lm
, -li
);
266 if (li
> 0 || li
<= -LDBL_MIN
)
268 puts ("nexttowardl- failed");
271 if (fetestexcept (FE_UNDERFLOW
) == 0)
273 puts ("nexttowardl- did not underflow");
277 feclearexcept (FE_ALL_EXCEPT
);
278 lm
= nexttowardl (zero
, inf
);
279 if (lm
< 0.0 || lm
>= LDBL_MIN
)
281 puts ("nexttowardl+ failed");
284 if (fetestexcept (FE_UNDERFLOW
) == 0)
286 puts ("nexttowardl+ did not underflow");
289 feclearexcept (FE_ALL_EXCEPT
);
290 if (nexttowardl (lm
, li
) != 0.0)
292 puts ("nexttowardl+ failed");
295 if (fetestexcept (FE_UNDERFLOW
) == 0)
297 puts ("nexttowardl+ did not underflow");
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");
307 if (fetestexcept (FE_UNDERFLOW
) == 0)
309 puts ("nexttowardl- did not underflow");
312 feclearexcept (FE_ALL_EXCEPT
);
313 if (nexttowardl (lm
, -li
) != 0.0)
315 puts ("nexttowardl- failed");
318 if (fetestexcept (FE_UNDERFLOW
) == 0)
320 puts ("nexttowardl- did not underflow");