t_next.c revision 1.4 1 1.4 riastrad /* $NetBSD: t_next.c,v 1.4 2024/05/08 17:27:03 riastradh Exp $ */
2 1.1 riastrad
3 1.1 riastrad /*-
4 1.1 riastrad * Copyright (c) 2024 The NetBSD Foundation, Inc.
5 1.1 riastrad * All rights reserved.
6 1.1 riastrad *
7 1.1 riastrad * Redistribution and use in source and binary forms, with or without
8 1.1 riastrad * modification, are permitted provided that the following conditions
9 1.1 riastrad * are met:
10 1.1 riastrad * 1. Redistributions of source code must retain the above copyright
11 1.1 riastrad * notice, this list of conditions and the following disclaimer.
12 1.1 riastrad * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 riastrad * notice, this list of conditions and the following disclaimer in the
14 1.1 riastrad * documentation and/or other materials provided with the distribution.
15 1.1 riastrad *
16 1.1 riastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.1 riastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.1 riastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.1 riastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.1 riastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 riastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 riastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 riastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 riastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 riastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 riastrad * POSSIBILITY OF SUCH DAMAGE.
27 1.1 riastrad */
28 1.1 riastrad
29 1.1 riastrad #include <sys/cdefs.h>
30 1.4 riastrad __RCSID("$NetBSD: t_next.c,v 1.4 2024/05/08 17:27:03 riastradh Exp $");
31 1.1 riastrad
32 1.1 riastrad #include <atf-c.h>
33 1.1 riastrad #include <float.h>
34 1.1 riastrad #include <math.h>
35 1.1 riastrad
36 1.2 riastrad #ifdef __vax__ /* XXX PR 57881: vax libm is missing various symbols */
37 1.2 riastrad
38 1.3 riastrad ATF_TC(vaxafter);
39 1.2 riastrad ATF_TC_HEAD(vaxafter, tc)
40 1.2 riastrad {
41 1.2 riastrad
42 1.3 riastrad atf_tc_set_md_var(tc, "descr", "vax nextafter/nexttoward reminder");
43 1.3 riastrad }
44 1.3 riastrad ATF_TC_BODY(vaxafter, tc)
45 1.3 riastrad {
46 1.3 riastrad
47 1.3 riastrad atf_tc_expect_fail("PR 57881: vax libm is missing various symbols");
48 1.2 riastrad atf_tc_fail("missing nextafter{,f,l} and nexttoward{,f,l} on vax");
49 1.2 riastrad }
50 1.2 riastrad
51 1.2 riastrad #else /* !__vax__ */
52 1.2 riastrad
53 1.4 riastrad #define CHECK(i, next, x, d, y) do \
54 1.4 riastrad { \
55 1.4 riastrad volatile __typeof__(x) check_x = (x); \
56 1.4 riastrad volatile __typeof__(d) check_d = (d); \
57 1.4 riastrad volatile __typeof__(y) check_y = (y); \
58 1.4 riastrad const volatile __typeof__(y) check_tmp = (next)(check_x, check_d); \
59 1.4 riastrad ATF_CHECK_MSG(check_tmp == check_y, \
60 1.4 riastrad "[%u] %s(%s=%La=%Lg, %s=%La=%Lg)=%La=%Lg != %s=%La=%Lg", \
61 1.4 riastrad (i), #next, \
62 1.4 riastrad #x, (long double)check_x, (long double)check_x, \
63 1.4 riastrad #d, (long double)check_d, (long double)check_d, \
64 1.4 riastrad (long double)check_tmp, (long double)check_tmp, \
65 1.4 riastrad #y, (long double)check_y, (long double)check_y); \
66 1.4 riastrad } while (0)
67 1.1 riastrad
68 1.4 riastrad /*
69 1.4 riastrad * check(x, n)
70 1.4 riastrad *
71 1.4 riastrad * x[0], x[1], ..., x[n - 1] are consecutive double floating-point
72 1.4 riastrad * numbers. Verify nextafter and nexttoward follow exactly this
73 1.4 riastrad * sequence, forward and back, and in negative.
74 1.4 riastrad */
75 1.4 riastrad static void
76 1.4 riastrad check(const double *x, unsigned n)
77 1.4 riastrad {
78 1.4 riastrad unsigned i;
79 1.4 riastrad
80 1.4 riastrad for (i = 0; i < n; i++) {
81 1.4 riastrad CHECK(i, nextafter, x[i], x[i], x[i]);
82 1.4 riastrad CHECK(i, nexttoward, x[i], x[i], x[i]);
83 1.4 riastrad CHECK(i, nextafter, -x[i], -x[i], -x[i]);
84 1.4 riastrad CHECK(i, nexttoward, -x[i], -x[i], -x[i]);
85 1.4 riastrad }
86 1.4 riastrad
87 1.4 riastrad for (i = 0; i < n - 1; i++) {
88 1.4 riastrad ATF_REQUIRE_MSG(x[i] < x[i + 1], "i=%u", i);
89 1.4 riastrad
90 1.4 riastrad if (isnormal(x[i])) {
91 1.4 riastrad CHECK(i, nexttoward, x[i], x[i]*(1 + LDBL_EPSILON),
92 1.4 riastrad x[i + 1]);
93 1.4 riastrad }
94 1.4 riastrad
95 1.4 riastrad CHECK(i, nextafter, x[i], x[i + 1], x[i + 1]);
96 1.4 riastrad CHECK(i, nexttoward, x[i], x[i + 1], x[i + 1]);
97 1.4 riastrad CHECK(i, nextafter, x[i], x[n - 1], x[i + 1]);
98 1.4 riastrad CHECK(i, nexttoward, x[i], x[n - 1], x[i + 1]);
99 1.4 riastrad CHECK(i, nextafter, x[i], INFINITY, x[i + 1]);
100 1.4 riastrad CHECK(i, nexttoward, x[i], INFINITY, x[i + 1]);
101 1.4 riastrad
102 1.4 riastrad CHECK(i, nextafter, -x[i], -x[i + 1], -x[i + 1]);
103 1.4 riastrad CHECK(i, nexttoward, -x[i], -x[i + 1], -x[i + 1]);
104 1.4 riastrad CHECK(i, nextafter, -x[i], -x[n - 1], -x[i + 1]);
105 1.4 riastrad CHECK(i, nexttoward, -x[i], -x[n - 1], -x[i + 1]);
106 1.4 riastrad CHECK(i, nextafter, -x[i], -INFINITY, -x[i + 1]);
107 1.4 riastrad CHECK(i, nexttoward, -x[i], -INFINITY, -x[i + 1]);
108 1.4 riastrad }
109 1.4 riastrad
110 1.4 riastrad for (i = n; i --> 1;) {
111 1.4 riastrad ATF_REQUIRE_MSG(x[i - 1] < x[i], "i=%u", i);
112 1.4 riastrad
113 1.4 riastrad if (isnormal(x[i])) {
114 1.4 riastrad CHECK(i, nexttoward, x[i], x[i]*(1 - LDBL_EPSILON/2),
115 1.4 riastrad x[i - 1]);
116 1.4 riastrad }
117 1.4 riastrad
118 1.4 riastrad CHECK(i, nextafter, x[i], x[i - 1], x[i - 1]);
119 1.4 riastrad CHECK(i, nexttoward, x[i], x[i - 1], x[i - 1]);
120 1.4 riastrad CHECK(i, nextafter, x[i], x[0], x[i - 1]);
121 1.4 riastrad CHECK(i, nexttoward, x[i], x[0], x[i - 1]);
122 1.4 riastrad CHECK(i, nextafter, x[i], +0., x[i - 1]);
123 1.4 riastrad CHECK(i, nexttoward, x[i], +0., x[i - 1]);
124 1.4 riastrad CHECK(i, nextafter, x[i], -0., x[i - 1]);
125 1.4 riastrad CHECK(i, nexttoward, x[i], -0., x[i - 1]);
126 1.4 riastrad CHECK(i, nextafter, x[i], -x[0], x[i - 1]);
127 1.4 riastrad CHECK(i, nexttoward, x[i], -x[0], x[i - 1]);
128 1.4 riastrad CHECK(i, nextafter, x[i], -x[i], x[i - 1]);
129 1.4 riastrad CHECK(i, nexttoward, x[i], -x[i], x[i - 1]);
130 1.4 riastrad CHECK(i, nextafter, x[i], -INFINITY, x[i - 1]);
131 1.4 riastrad CHECK(i, nexttoward, x[i], -INFINITY, x[i - 1]);
132 1.4 riastrad
133 1.4 riastrad CHECK(i, nextafter, -x[i], -x[i - 1], -x[i - 1]);
134 1.4 riastrad CHECK(i, nexttoward, -x[i], -x[i - 1], -x[i - 1]);
135 1.4 riastrad CHECK(i, nextafter, -x[i], -x[0], -x[i - 1]);
136 1.4 riastrad CHECK(i, nexttoward, -x[i], -x[0], -x[i - 1]);
137 1.4 riastrad CHECK(i, nextafter, -x[i], -0., -x[i - 1]);
138 1.4 riastrad CHECK(i, nexttoward, -x[i], -0., -x[i - 1]);
139 1.4 riastrad CHECK(i, nextafter, -x[i], +0., -x[i - 1]);
140 1.4 riastrad CHECK(i, nexttoward, -x[i], +0., -x[i - 1]);
141 1.4 riastrad CHECK(i, nextafter, -x[i], x[0], -x[i - 1]);
142 1.4 riastrad CHECK(i, nexttoward, -x[i], x[0], -x[i - 1]);
143 1.4 riastrad CHECK(i, nextafter, -x[i], INFINITY, -x[i - 1]);
144 1.4 riastrad CHECK(i, nexttoward, -x[i], INFINITY, -x[i - 1]);
145 1.4 riastrad }
146 1.4 riastrad }
147 1.4 riastrad
148 1.4 riastrad /*
149 1.4 riastrad * checkf(x, n)
150 1.4 riastrad *
151 1.4 riastrad * x[0], x[1], ..., x[n - 1] are consecutive single floating-point
152 1.4 riastrad * numbers. Verify nextafterf and nexttowardf follow exactly this
153 1.4 riastrad * sequence, forward and back, and in negative.
154 1.4 riastrad */
155 1.4 riastrad static void
156 1.4 riastrad checkf(const float *x, unsigned n)
157 1.4 riastrad {
158 1.4 riastrad unsigned i;
159 1.4 riastrad
160 1.4 riastrad for (i = 0; i < n; i++) {
161 1.4 riastrad CHECK(i, nextafterf, x[i], x[i], x[i]);
162 1.4 riastrad CHECK(i, nexttowardf, x[i], x[i], x[i]);
163 1.4 riastrad CHECK(i, nextafterf, -x[i], -x[i], -x[i]);
164 1.4 riastrad CHECK(i, nexttowardf, -x[i], -x[i], -x[i]);
165 1.4 riastrad }
166 1.4 riastrad
167 1.4 riastrad for (i = 0; i < n - 1; i++) {
168 1.4 riastrad ATF_REQUIRE_MSG(x[i] < x[i + 1], "i=%u", i);
169 1.4 riastrad
170 1.4 riastrad if (isnormal(x[i])) {
171 1.4 riastrad CHECK(i, nexttowardf, x[i], x[i]*(1 + LDBL_EPSILON),
172 1.4 riastrad x[i + 1]);
173 1.4 riastrad }
174 1.4 riastrad
175 1.4 riastrad CHECK(i, nextafterf, x[i], x[i + 1], x[i + 1]);
176 1.4 riastrad CHECK(i, nexttowardf, x[i], x[i + 1], x[i + 1]);
177 1.4 riastrad CHECK(i, nextafterf, x[i], x[n - 1], x[i + 1]);
178 1.4 riastrad CHECK(i, nexttowardf, x[i], x[n - 1], x[i + 1]);
179 1.4 riastrad CHECK(i, nextafterf, x[i], INFINITY, x[i + 1]);
180 1.4 riastrad CHECK(i, nexttowardf, x[i], INFINITY, x[i + 1]);
181 1.4 riastrad
182 1.4 riastrad CHECK(i, nextafterf, -x[i], -x[i + 1], -x[i + 1]);
183 1.4 riastrad CHECK(i, nexttowardf, -x[i], -x[i + 1], -x[i + 1]);
184 1.4 riastrad CHECK(i, nextafterf, -x[i], -x[n - 1], -x[i + 1]);
185 1.4 riastrad CHECK(i, nexttowardf, -x[i], -x[n - 1], -x[i + 1]);
186 1.4 riastrad CHECK(i, nextafterf, -x[i], -INFINITY, -x[i + 1]);
187 1.4 riastrad CHECK(i, nexttowardf, -x[i], -INFINITY, -x[i + 1]);
188 1.4 riastrad }
189 1.4 riastrad
190 1.4 riastrad for (i = n; i --> 1;) {
191 1.4 riastrad ATF_REQUIRE_MSG(x[i - 1] < x[i], "i=%u", i);
192 1.4 riastrad
193 1.4 riastrad if (isnormal(x[i])) {
194 1.4 riastrad CHECK(i, nexttowardf, x[i], x[i]*(1 - LDBL_EPSILON/2),
195 1.4 riastrad x[i - 1]);
196 1.4 riastrad }
197 1.4 riastrad
198 1.4 riastrad CHECK(i, nextafterf, x[i], x[i - 1], x[i - 1]);
199 1.4 riastrad CHECK(i, nexttowardf, x[i], x[i - 1], x[i - 1]);
200 1.4 riastrad CHECK(i, nextafterf, x[i], x[0], x[i - 1]);
201 1.4 riastrad CHECK(i, nexttowardf, x[i], x[0], x[i - 1]);
202 1.4 riastrad CHECK(i, nextafterf, x[i], +0., x[i - 1]);
203 1.4 riastrad CHECK(i, nexttowardf, x[i], +0., x[i - 1]);
204 1.4 riastrad CHECK(i, nextafterf, x[i], -0., x[i - 1]);
205 1.4 riastrad CHECK(i, nexttowardf, x[i], -0., x[i - 1]);
206 1.4 riastrad CHECK(i, nextafterf, x[i], -x[0], x[i - 1]);
207 1.4 riastrad CHECK(i, nexttowardf, x[i], -x[0], x[i - 1]);
208 1.4 riastrad CHECK(i, nextafterf, x[i], -x[i], x[i - 1]);
209 1.4 riastrad CHECK(i, nexttowardf, x[i], -x[i], x[i - 1]);
210 1.4 riastrad CHECK(i, nextafterf, x[i], -INFINITY, x[i - 1]);
211 1.4 riastrad CHECK(i, nexttowardf, x[i], -INFINITY, x[i - 1]);
212 1.4 riastrad
213 1.4 riastrad CHECK(i, nextafterf, -x[i], -x[i - 1], -x[i - 1]);
214 1.4 riastrad CHECK(i, nexttowardf, -x[i], -x[i - 1], -x[i - 1]);
215 1.4 riastrad CHECK(i, nextafterf, -x[i], -x[0], -x[i - 1]);
216 1.4 riastrad CHECK(i, nexttowardf, -x[i], -x[0], -x[i - 1]);
217 1.4 riastrad CHECK(i, nextafterf, -x[i], -0., -x[i - 1]);
218 1.4 riastrad CHECK(i, nexttowardf, -x[i], -0., -x[i - 1]);
219 1.4 riastrad CHECK(i, nextafterf, -x[i], +0., -x[i - 1]);
220 1.4 riastrad CHECK(i, nexttowardf, -x[i], +0., -x[i - 1]);
221 1.4 riastrad CHECK(i, nextafterf, -x[i], x[0], -x[i - 1]);
222 1.4 riastrad CHECK(i, nexttowardf, -x[i], x[0], -x[i - 1]);
223 1.4 riastrad CHECK(i, nextafterf, -x[i], INFINITY, -x[i - 1]);
224 1.4 riastrad CHECK(i, nexttowardf, -x[i], INFINITY, -x[i - 1]);
225 1.4 riastrad }
226 1.4 riastrad }
227 1.4 riastrad
228 1.4 riastrad /*
229 1.4 riastrad * checkl(x, n)
230 1.4 riastrad *
231 1.4 riastrad * x[0], x[1], ..., x[n - 1] are consecutive long double
232 1.4 riastrad * floating-point numbers. Verify nextafterl and nexttowardl
233 1.4 riastrad * follow exactly this sequence, forward and back, and in
234 1.4 riastrad * negative.
235 1.4 riastrad */
236 1.4 riastrad static void
237 1.4 riastrad checkl(const long double *x, unsigned n)
238 1.4 riastrad {
239 1.4 riastrad unsigned i;
240 1.4 riastrad
241 1.4 riastrad for (i = 0; i < n; i++) {
242 1.4 riastrad CHECK(i, nextafterl, x[i], x[i], x[i]);
243 1.4 riastrad CHECK(i, nexttowardl, x[i], x[i], x[i]);
244 1.4 riastrad CHECK(i, nextafterl, -x[i], -x[i], -x[i]);
245 1.4 riastrad CHECK(i, nexttowardl, -x[i], -x[i], -x[i]);
246 1.4 riastrad }
247 1.4 riastrad
248 1.4 riastrad for (i = 0; i < n - 1; i++) {
249 1.4 riastrad ATF_REQUIRE_MSG(x[i] < x[i + 1], "i=%u", i);
250 1.4 riastrad
251 1.4 riastrad CHECK(i, nextafterl, x[i], x[i + 1], x[i + 1]);
252 1.4 riastrad CHECK(i, nexttowardl, x[i], x[i + 1], x[i + 1]);
253 1.4 riastrad CHECK(i, nextafterl, x[i], x[n - 1], x[i + 1]);
254 1.4 riastrad CHECK(i, nexttowardl, x[i], x[n - 1], x[i + 1]);
255 1.4 riastrad CHECK(i, nextafterl, x[i], INFINITY, x[i + 1]);
256 1.4 riastrad CHECK(i, nexttowardl, x[i], INFINITY, x[i + 1]);
257 1.4 riastrad
258 1.4 riastrad CHECK(i, nextafterl, -x[i], -x[i + 1], -x[i + 1]);
259 1.4 riastrad CHECK(i, nexttowardl, -x[i], -x[i + 1], -x[i + 1]);
260 1.4 riastrad CHECK(i, nextafterl, -x[i], -x[n - 1], -x[i + 1]);
261 1.4 riastrad CHECK(i, nexttowardl, -x[i], -x[n - 1], -x[i + 1]);
262 1.4 riastrad CHECK(i, nextafterl, -x[i], -INFINITY, -x[i + 1]);
263 1.4 riastrad CHECK(i, nexttowardl, -x[i], -INFINITY, -x[i + 1]);
264 1.4 riastrad }
265 1.4 riastrad
266 1.4 riastrad for (i = n; i --> 1;) {
267 1.4 riastrad ATF_REQUIRE_MSG(x[i - 1] < x[i], "i=%u", i);
268 1.4 riastrad
269 1.4 riastrad CHECK(i, nextafterl, x[i], x[i - 1], x[i - 1]);
270 1.4 riastrad CHECK(i, nexttowardl, x[i], x[i - 1], x[i - 1]);
271 1.4 riastrad CHECK(i, nextafterl, x[i], x[0], x[i - 1]);
272 1.4 riastrad CHECK(i, nexttowardl, x[i], x[0], x[i - 1]);
273 1.4 riastrad CHECK(i, nextafterl, x[i], +0., x[i - 1]);
274 1.4 riastrad CHECK(i, nexttowardl, x[i], +0., x[i - 1]);
275 1.4 riastrad CHECK(i, nextafterl, x[i], -0., x[i - 1]);
276 1.4 riastrad CHECK(i, nexttowardl, x[i], -0., x[i - 1]);
277 1.4 riastrad CHECK(i, nextafterl, x[i], -x[0], x[i - 1]);
278 1.4 riastrad CHECK(i, nexttowardl, x[i], -x[0], x[i - 1]);
279 1.4 riastrad CHECK(i, nextafterl, x[i], -x[i], x[i - 1]);
280 1.4 riastrad CHECK(i, nexttowardl, x[i], -x[i], x[i - 1]);
281 1.4 riastrad CHECK(i, nextafterl, x[i], -INFINITY, x[i - 1]);
282 1.4 riastrad CHECK(i, nexttowardl, x[i], -INFINITY, x[i - 1]);
283 1.4 riastrad
284 1.4 riastrad CHECK(i, nextafterl, -x[i], -x[i - 1], -x[i - 1]);
285 1.4 riastrad CHECK(i, nexttowardl, -x[i], -x[i - 1], -x[i - 1]);
286 1.4 riastrad CHECK(i, nextafterl, -x[i], -x[0], -x[i - 1]);
287 1.4 riastrad CHECK(i, nexttowardl, -x[i], -x[0], -x[i - 1]);
288 1.4 riastrad CHECK(i, nextafterl, -x[i], -0., -x[i - 1]);
289 1.4 riastrad CHECK(i, nexttowardl, -x[i], -0., -x[i - 1]);
290 1.4 riastrad CHECK(i, nextafterl, -x[i], +0., -x[i - 1]);
291 1.4 riastrad CHECK(i, nexttowardl, -x[i], +0., -x[i - 1]);
292 1.4 riastrad CHECK(i, nextafterl, -x[i], x[0], -x[i - 1]);
293 1.4 riastrad CHECK(i, nexttowardl, -x[i], x[0], -x[i - 1]);
294 1.4 riastrad CHECK(i, nextafterl, -x[i], INFINITY, -x[i - 1]);
295 1.4 riastrad CHECK(i, nexttowardl, -x[i], INFINITY, -x[i - 1]);
296 1.4 riastrad }
297 1.4 riastrad }
298 1.4 riastrad
299 1.4 riastrad ATF_TC(next_nan);
300 1.4 riastrad ATF_TC_HEAD(next_nan, tc)
301 1.4 riastrad {
302 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward on NaN");
303 1.4 riastrad }
304 1.4 riastrad ATF_TC_BODY(next_nan, tc)
305 1.4 riastrad {
306 1.4 riastrad #ifdef NAN
307 1.4 riastrad /* XXX verify the NaN is quiet */
308 1.4 riastrad ATF_CHECK(isnan(nextafter(NAN, 0)));
309 1.4 riastrad ATF_CHECK(isnan(nexttoward(NAN, 0)));
310 1.4 riastrad ATF_CHECK(isnan(nextafter(0, NAN)));
311 1.4 riastrad ATF_CHECK(isnan(nexttoward(0, NAN)));
312 1.4 riastrad #else
313 1.4 riastrad atf_tc_skip("no NaNs on this architecture");
314 1.4 riastrad #endif
315 1.4 riastrad }
316 1.4 riastrad
317 1.4 riastrad ATF_TC(next_signed_0);
318 1.4 riastrad ATF_TC_HEAD(next_signed_0, tc)
319 1.4 riastrad {
320 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward on signed 0");
321 1.4 riastrad }
322 1.4 riastrad ATF_TC_BODY(next_signed_0, tc)
323 1.4 riastrad {
324 1.4 riastrad volatile double z_pos = +0.;
325 1.4 riastrad volatile double z_neg = -0.;
326 1.4 riastrad #ifdef __DBL_HAS_DENORM__
327 1.4 riastrad volatile double m = __DBL_DENORM_MIN__;
328 1.4 riastrad #else
329 1.4 riastrad volatile double m = DBL_MIN;
330 1.4 riastrad #endif
331 1.4 riastrad
332 1.4 riastrad if (signbit(z_pos) == signbit(z_neg))
333 1.4 riastrad atf_tc_skip("no signed zeroes on this architecture");
334 1.4 riastrad
335 1.4 riastrad /*
336 1.4 riastrad * `nextUp(x) is the least floating-point number in the format
337 1.4 riastrad * of x that compares greater than x. [...] nextDown(x) is
338 1.4 riastrad * -nextUp(-x).'
339 1.4 riastrad * --IEEE 754-2019, 5.3.1 General operations, p. 19
340 1.4 riastrad *
341 1.4 riastrad * Verify that nextafter and nexttoward, which implement the
342 1.4 riastrad * nextUp and nextDown operations, obey this rule and don't
343 1.4 riastrad * send -0 to +0 or +0 to -0, respectively.
344 1.4 riastrad */
345 1.4 riastrad
346 1.4 riastrad CHECK(0, nextafter, z_neg, +INFINITY, m);
347 1.4 riastrad CHECK(1, nexttoward, z_neg, +INFINITY, m);
348 1.4 riastrad CHECK(2, nextafter, z_pos, +INFINITY, m);
349 1.4 riastrad CHECK(3, nexttoward, z_pos, +INFINITY, m);
350 1.4 riastrad
351 1.4 riastrad CHECK(4, nextafter, z_pos, -INFINITY, -m);
352 1.4 riastrad CHECK(5, nexttoward, z_pos, -INFINITY, -m);
353 1.4 riastrad CHECK(6, nextafter, z_neg, -INFINITY, -m);
354 1.4 riastrad CHECK(7, nexttoward, z_neg, -INFINITY, -m);
355 1.4 riastrad
356 1.4 riastrad /*
357 1.4 riastrad * `If x is the negative number of least magnitude in x's
358 1.4 riastrad * format, nextUp(x) is -0.'
359 1.4 riastrad * --IEEE 754-2019, 5.3.1 General operations, p. 19
360 1.4 riastrad *
361 1.4 riastrad * Verify that nextafter and nexttoward return the correctly
362 1.4 riastrad * signed zero.
363 1.4 riastrad */
364 1.4 riastrad CHECK(8, nextafter, -m, +INFINITY, 0);
365 1.4 riastrad CHECK(9, nexttoward, -m, +INFINITY, 0);
366 1.4 riastrad ATF_CHECK(signbit(nextafter(-m, +INFINITY)) != 0);
367 1.4 riastrad CHECK(10, nextafter, m, -INFINITY, 0);
368 1.4 riastrad CHECK(11, nexttoward, m, -INFINITY, 0);
369 1.4 riastrad ATF_CHECK(signbit(nextafter(m, -INFINITY)) == 0);
370 1.4 riastrad }
371 1.4 riastrad
372 1.4 riastrad ATF_TC(next_near_0);
373 1.4 riastrad ATF_TC_HEAD(next_near_0, tc)
374 1.4 riastrad {
375 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near 0");
376 1.4 riastrad }
377 1.4 riastrad ATF_TC_BODY(next_near_0, tc)
378 1.4 riastrad {
379 1.4 riastrad static const double x[] = {
380 1.4 riastrad [0] = 0,
381 1.4 riastrad #ifdef __DBL_HAS_DENORM__
382 1.4 riastrad [1] = __DBL_DENORM_MIN__,
383 1.4 riastrad [2] = 2*__DBL_DENORM_MIN__,
384 1.4 riastrad [3] = 3*__DBL_DENORM_MIN__,
385 1.4 riastrad [4] = 4*__DBL_DENORM_MIN__,
386 1.4 riastrad #else
387 1.4 riastrad [1] = DBL_MIN,
388 1.4 riastrad [2] = DBL_MIN*(1 + DBL_EPSILON),
389 1.4 riastrad [3] = DBL_MIN*(1 + 2*DBL_EPSILON),
390 1.4 riastrad [4] = DBL_MIN*(1 + 3*DBL_EPSILON),
391 1.4 riastrad #endif
392 1.4 riastrad };
393 1.4 riastrad
394 1.4 riastrad atf_tc_expect_fail("PR 58236: nexttoward(3) is broken on subnormals");
395 1.4 riastrad check(x, __arraycount(x));
396 1.4 riastrad }
397 1.4 riastrad
398 1.4 riastrad ATF_TC(next_near_sub_normal);
399 1.4 riastrad ATF_TC_HEAD(next_near_sub_normal, tc)
400 1.4 riastrad {
401 1.4 riastrad atf_tc_set_md_var(tc, "descr",
402 1.4 riastrad "nextafter/nexttoward near the subnormal/normal boundary");
403 1.4 riastrad }
404 1.4 riastrad ATF_TC_BODY(next_near_sub_normal, tc)
405 1.4 riastrad {
406 1.4 riastrad #ifdef __DBL_HAS_DENORM__
407 1.4 riastrad static const double x[] = {
408 1.4 riastrad [0] = DBL_MIN - 3*__DBL_DENORM_MIN__,
409 1.4 riastrad [1] = DBL_MIN - 2*__DBL_DENORM_MIN__,
410 1.4 riastrad [2] = DBL_MIN - __DBL_DENORM_MIN__,
411 1.4 riastrad [3] = DBL_MIN,
412 1.4 riastrad [4] = DBL_MIN + __DBL_DENORM_MIN__,
413 1.4 riastrad [5] = DBL_MIN + 2*__DBL_DENORM_MIN__,
414 1.4 riastrad [6] = DBL_MIN + 3*__DBL_DENORM_MIN__,
415 1.4 riastrad };
416 1.4 riastrad
417 1.4 riastrad check(x, __arraycount(x));
418 1.4 riastrad #else /* !__DBL_HAS_DENORM__ */
419 1.4 riastrad atf_tc_skip("no subnormals on this architecture");
420 1.4 riastrad #endif /* !__DBL_HAS_DENORM__ */
421 1.4 riastrad }
422 1.4 riastrad
423 1.4 riastrad ATF_TC(next_near_1);
424 1.4 riastrad ATF_TC_HEAD(next_near_1, tc)
425 1.4 riastrad {
426 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near 1");
427 1.4 riastrad }
428 1.4 riastrad ATF_TC_BODY(next_near_1, tc)
429 1.4 riastrad {
430 1.4 riastrad static const double x[] = {
431 1.4 riastrad [0] = 1 - 3*DBL_EPSILON/2,
432 1.4 riastrad [1] = 1 - 2*DBL_EPSILON/2,
433 1.4 riastrad [2] = 1 - DBL_EPSILON/2,
434 1.4 riastrad [3] = 1,
435 1.4 riastrad [4] = 1 + DBL_EPSILON,
436 1.4 riastrad [5] = 1 + 2*DBL_EPSILON,
437 1.4 riastrad [6] = 1 + 3*DBL_EPSILON,
438 1.4 riastrad };
439 1.4 riastrad
440 1.4 riastrad check(x, __arraycount(x));
441 1.4 riastrad }
442 1.4 riastrad
443 1.4 riastrad ATF_TC(next_near_1_5);
444 1.4 riastrad ATF_TC_HEAD(next_near_1_5, tc)
445 1.4 riastrad {
446 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near 1.5");
447 1.4 riastrad }
448 1.4 riastrad ATF_TC_BODY(next_near_1_5, tc)
449 1.4 riastrad {
450 1.4 riastrad static const double x[] = {
451 1.4 riastrad [0] = 1.5 - 3*DBL_EPSILON,
452 1.4 riastrad [1] = 1.5 - 2*DBL_EPSILON,
453 1.4 riastrad [2] = 1.5 - DBL_EPSILON,
454 1.4 riastrad [3] = 1.5,
455 1.4 riastrad [4] = 1.5 + DBL_EPSILON,
456 1.4 riastrad [5] = 1.5 + 2*DBL_EPSILON,
457 1.4 riastrad [6] = 1.5 + 3*DBL_EPSILON,
458 1.4 riastrad };
459 1.4 riastrad
460 1.4 riastrad check(x, __arraycount(x));
461 1.4 riastrad }
462 1.4 riastrad
463 1.4 riastrad ATF_TC(next_near_infinity);
464 1.4 riastrad ATF_TC_HEAD(next_near_infinity, tc)
465 1.4 riastrad {
466 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near infinity");
467 1.4 riastrad }
468 1.4 riastrad ATF_TC_BODY(next_near_infinity, tc)
469 1.4 riastrad {
470 1.4 riastrad static const double x[] = {
471 1.4 riastrad [0] = DBL_MAX,
472 1.4 riastrad [1] = INFINITY,
473 1.4 riastrad };
474 1.4 riastrad volatile double t;
475 1.4 riastrad
476 1.4 riastrad if (!isinf(INFINITY))
477 1.4 riastrad atf_tc_skip("no infinities on this architecture");
478 1.4 riastrad
479 1.4 riastrad check(x, __arraycount(x));
480 1.4 riastrad
481 1.4 riastrad ATF_CHECK_EQ_MSG((t = nextafter(INFINITY, INFINITY)), INFINITY,
482 1.4 riastrad "t=%a=%g", t, t);
483 1.4 riastrad ATF_CHECK_EQ_MSG((t = nextafter(-INFINITY, -INFINITY)), -INFINITY,
484 1.4 riastrad "t=%a=%g", t, t);
485 1.4 riastrad }
486 1.4 riastrad
487 1.4 riastrad ATF_TC(nextf_nan);
488 1.4 riastrad ATF_TC_HEAD(nextf_nan, tc)
489 1.4 riastrad {
490 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf on NaN");
491 1.4 riastrad }
492 1.4 riastrad ATF_TC_BODY(nextf_nan, tc)
493 1.4 riastrad {
494 1.4 riastrad #ifdef NAN
495 1.4 riastrad /* XXX verify the NaN is quiet */
496 1.4 riastrad ATF_CHECK(isnan(nextafterf(NAN, 0)));
497 1.4 riastrad ATF_CHECK(isnan(nexttowardf(NAN, 0)));
498 1.4 riastrad ATF_CHECK(isnan(nextafterf(0, NAN)));
499 1.4 riastrad ATF_CHECK(isnan(nexttowardf(0, NAN)));
500 1.4 riastrad #else
501 1.4 riastrad atf_tc_skip("no NaNs on this architecture");
502 1.4 riastrad #endif
503 1.4 riastrad }
504 1.4 riastrad
505 1.4 riastrad ATF_TC(nextf_signed_0);
506 1.4 riastrad ATF_TC_HEAD(nextf_signed_0, tc)
507 1.4 riastrad {
508 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf on signed 0");
509 1.4 riastrad }
510 1.4 riastrad ATF_TC_BODY(nextf_signed_0, tc)
511 1.4 riastrad {
512 1.4 riastrad volatile float z_pos = +0.;
513 1.4 riastrad volatile float z_neg = -0.;
514 1.4 riastrad #ifdef __FLT_HAS_DENORM__
515 1.4 riastrad volatile float m = __FLT_DENORM_MIN__;
516 1.4 riastrad #else
517 1.4 riastrad volatile float m = FLT_MIN;
518 1.4 riastrad #endif
519 1.4 riastrad
520 1.4 riastrad if (signbit(z_pos) == signbit(z_neg))
521 1.4 riastrad atf_tc_skip("no signed zeroes on this architecture");
522 1.4 riastrad
523 1.4 riastrad /*
524 1.4 riastrad * `nextUp(x) is the least floating-point number in the format
525 1.4 riastrad * of x that compares greater than x. [...] nextDown(x) is
526 1.4 riastrad * -nextUp(-x).'
527 1.4 riastrad * --IEEE 754-2019, 5.3.1 General operations, p. 19
528 1.4 riastrad *
529 1.4 riastrad * Verify that nextafterf and nexttowardf, which implement the
530 1.4 riastrad * nextUp and nextDown operations, obey this rule and don't
531 1.4 riastrad * send -0 to +0 or +0 to -0, respectively.
532 1.4 riastrad */
533 1.4 riastrad
534 1.4 riastrad CHECK(0, nextafterf, z_neg, +INFINITY, m);
535 1.4 riastrad CHECK(1, nexttowardf, z_neg, +INFINITY, m);
536 1.4 riastrad CHECK(2, nextafterf, z_pos, +INFINITY, m);
537 1.4 riastrad CHECK(3, nexttowardf, z_pos, +INFINITY, m);
538 1.4 riastrad
539 1.4 riastrad CHECK(4, nextafterf, z_pos, -INFINITY, -m);
540 1.4 riastrad CHECK(5, nexttowardf, z_pos, -INFINITY, -m);
541 1.4 riastrad CHECK(6, nextafterf, z_neg, -INFINITY, -m);
542 1.4 riastrad CHECK(7, nexttowardf, z_neg, -INFINITY, -m);
543 1.4 riastrad
544 1.4 riastrad /*
545 1.4 riastrad * `If x is the negative number of least magnitude in x's
546 1.4 riastrad * format, nextUp(x) is -0.'
547 1.4 riastrad * --IEEE 754-2019, 5.3.1 General operations, p. 19
548 1.4 riastrad */
549 1.4 riastrad CHECK(8, nextafterf, -m, +INFINITY, 0);
550 1.4 riastrad CHECK(9, nexttowardf, -m, +INFINITY, 0);
551 1.4 riastrad ATF_CHECK(signbit(nextafterf(-m, +INFINITY)) != 0);
552 1.4 riastrad CHECK(10, nextafterf, m, -INFINITY, 0);
553 1.4 riastrad CHECK(11, nexttowardf, m, -INFINITY, 0);
554 1.4 riastrad ATF_CHECK(signbit(nextafterf(m, -INFINITY)) == 0);
555 1.4 riastrad }
556 1.4 riastrad
557 1.4 riastrad ATF_TC(nextf_near_0);
558 1.4 riastrad ATF_TC_HEAD(nextf_near_0, tc)
559 1.4 riastrad {
560 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near 0");
561 1.4 riastrad }
562 1.4 riastrad ATF_TC_BODY(nextf_near_0, tc)
563 1.4 riastrad {
564 1.4 riastrad static const float x[] = {
565 1.4 riastrad [0] = 0,
566 1.4 riastrad #ifdef __FLT_HAS_DENORM__
567 1.4 riastrad [1] = __FLT_DENORM_MIN__,
568 1.4 riastrad [2] = 2*__FLT_DENORM_MIN__,
569 1.4 riastrad [3] = 3*__FLT_DENORM_MIN__,
570 1.4 riastrad [4] = 4*__FLT_DENORM_MIN__,
571 1.4 riastrad #else
572 1.4 riastrad [1] = FLT_MIN,
573 1.4 riastrad [2] = FLT_MIN*(1 + FLT_EPSILON),
574 1.4 riastrad [3] = FLT_MIN*(1 + 2*FLT_EPSILON),
575 1.4 riastrad [4] = FLT_MIN*(1 + 3*FLT_EPSILON),
576 1.4 riastrad #endif
577 1.4 riastrad };
578 1.4 riastrad
579 1.4 riastrad checkf(x, __arraycount(x));
580 1.4 riastrad }
581 1.4 riastrad
582 1.4 riastrad ATF_TC(nextf_near_sub_normal);
583 1.4 riastrad ATF_TC_HEAD(nextf_near_sub_normal, tc)
584 1.4 riastrad {
585 1.4 riastrad atf_tc_set_md_var(tc, "descr",
586 1.4 riastrad "nextafterf/nexttowardf near the subnormal/normal boundary");
587 1.4 riastrad }
588 1.4 riastrad ATF_TC_BODY(nextf_near_sub_normal, tc)
589 1.4 riastrad {
590 1.4 riastrad #ifdef __FLT_HAS_DENORM__
591 1.4 riastrad static const float x[] = {
592 1.4 riastrad [0] = FLT_MIN - 3*__FLT_DENORM_MIN__,
593 1.4 riastrad [1] = FLT_MIN - 2*__FLT_DENORM_MIN__,
594 1.4 riastrad [2] = FLT_MIN - __FLT_DENORM_MIN__,
595 1.4 riastrad [3] = FLT_MIN,
596 1.4 riastrad [4] = FLT_MIN + __FLT_DENORM_MIN__,
597 1.4 riastrad [5] = FLT_MIN + 2*__FLT_DENORM_MIN__,
598 1.4 riastrad [6] = FLT_MIN + 3*__FLT_DENORM_MIN__,
599 1.4 riastrad };
600 1.4 riastrad
601 1.4 riastrad checkf(x, __arraycount(x));
602 1.4 riastrad #else /* !__FLT_HAS_DENORM__ */
603 1.4 riastrad atf_tc_skip("no subnormals on this architecture");
604 1.4 riastrad #endif /* !__FLT_HAS_DENORM__ */
605 1.4 riastrad }
606 1.4 riastrad
607 1.4 riastrad ATF_TC(nextf_near_1);
608 1.4 riastrad ATF_TC_HEAD(nextf_near_1, tc)
609 1.4 riastrad {
610 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near 1");
611 1.4 riastrad }
612 1.4 riastrad ATF_TC_BODY(nextf_near_1, tc)
613 1.4 riastrad {
614 1.4 riastrad static const float x[] = {
615 1.4 riastrad [0] = 1 - 3*FLT_EPSILON/2,
616 1.4 riastrad [1] = 1 - 2*FLT_EPSILON/2,
617 1.4 riastrad [2] = 1 - FLT_EPSILON/2,
618 1.4 riastrad [3] = 1,
619 1.4 riastrad [4] = 1 + FLT_EPSILON,
620 1.4 riastrad [5] = 1 + 2*FLT_EPSILON,
621 1.4 riastrad [6] = 1 + 3*FLT_EPSILON,
622 1.4 riastrad };
623 1.4 riastrad
624 1.4 riastrad checkf(x, __arraycount(x));
625 1.4 riastrad }
626 1.4 riastrad
627 1.4 riastrad ATF_TC(nextf_near_1_5);
628 1.4 riastrad ATF_TC_HEAD(nextf_near_1_5, tc)
629 1.4 riastrad {
630 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near 1.5");
631 1.4 riastrad }
632 1.4 riastrad ATF_TC_BODY(nextf_near_1_5, tc)
633 1.1 riastrad {
634 1.4 riastrad static const float x[] = {
635 1.4 riastrad [0] = 1.5 - 3*FLT_EPSILON,
636 1.4 riastrad [1] = 1.5 - 2*FLT_EPSILON,
637 1.4 riastrad [2] = 1.5 - FLT_EPSILON,
638 1.4 riastrad [3] = 1.5,
639 1.4 riastrad [4] = 1.5 + FLT_EPSILON,
640 1.4 riastrad [5] = 1.5 + 2*FLT_EPSILON,
641 1.4 riastrad [6] = 1.5 + 3*FLT_EPSILON,
642 1.4 riastrad };
643 1.4 riastrad
644 1.4 riastrad checkf(x, __arraycount(x));
645 1.4 riastrad }
646 1.4 riastrad
647 1.4 riastrad ATF_TC(nextf_near_infinity);
648 1.4 riastrad ATF_TC_HEAD(nextf_near_infinity, tc)
649 1.4 riastrad {
650 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near infinity");
651 1.1 riastrad }
652 1.4 riastrad ATF_TC_BODY(nextf_near_infinity, tc)
653 1.1 riastrad {
654 1.4 riastrad static const float x[] = {
655 1.4 riastrad [0] = FLT_MAX,
656 1.4 riastrad [1] = INFINITY,
657 1.4 riastrad };
658 1.4 riastrad volatile float t;
659 1.4 riastrad
660 1.4 riastrad if (!isinf(INFINITY))
661 1.4 riastrad atf_tc_skip("no infinities on this architecture");
662 1.4 riastrad
663 1.4 riastrad checkf(x, __arraycount(x));
664 1.4 riastrad
665 1.4 riastrad ATF_CHECK_EQ_MSG((t = nextafterf(INFINITY, INFINITY)), INFINITY,
666 1.4 riastrad "t=%a=%g", t, t);
667 1.4 riastrad ATF_CHECK_EQ_MSG((t = nextafterf(-INFINITY, -INFINITY)), -INFINITY,
668 1.4 riastrad "t=%a=%g", t, t);
669 1.4 riastrad }
670 1.1 riastrad
671 1.4 riastrad ATF_TC(nextl_nan);
672 1.4 riastrad ATF_TC_HEAD(nextl_nan, tc)
673 1.4 riastrad {
674 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl on NaN");
675 1.4 riastrad }
676 1.4 riastrad ATF_TC_BODY(nextl_nan, tc)
677 1.4 riastrad {
678 1.4 riastrad #ifdef NAN
679 1.4 riastrad /* XXX verify the NaN is quiet */
680 1.4 riastrad ATF_CHECK(isnan(nextafterl(NAN, 0)));
681 1.4 riastrad ATF_CHECK(isnan(nexttowardl(NAN, 0)));
682 1.4 riastrad ATF_CHECK(isnan(nextafterl(0, NAN)));
683 1.4 riastrad ATF_CHECK(isnan(nexttowardl(0, NAN)));
684 1.4 riastrad #else
685 1.4 riastrad atf_tc_skip("no NaNs on this architecture");
686 1.4 riastrad #endif
687 1.1 riastrad }
688 1.1 riastrad
689 1.4 riastrad ATF_TC(nextl_signed_0);
690 1.4 riastrad ATF_TC_HEAD(nextl_signed_0, tc)
691 1.1 riastrad {
692 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl on signed 0");
693 1.1 riastrad }
694 1.4 riastrad ATF_TC_BODY(nextl_signed_0, tc)
695 1.1 riastrad {
696 1.4 riastrad volatile long double z_pos = +0.;
697 1.4 riastrad volatile long double z_neg = -0.;
698 1.4 riastrad #ifdef __LDBL_HAS_DENORM__
699 1.4 riastrad volatile long double m = __LDBL_DENORM_MIN__;
700 1.4 riastrad #else
701 1.4 riastrad volatile long double m = LDBL_MIN;
702 1.4 riastrad #endif
703 1.4 riastrad
704 1.4 riastrad if (signbit(z_pos) == signbit(z_neg))
705 1.4 riastrad atf_tc_skip("no signed zeroes on this architecture");
706 1.1 riastrad
707 1.4 riastrad /*
708 1.4 riastrad * `nextUp(x) is the least floating-point number in the format
709 1.4 riastrad * of x that compares greater than x. [...] nextDown(x) is
710 1.4 riastrad * -nextUp(-x).'
711 1.4 riastrad * --IEEE 754-2019, 5.3.1 General operations, p. 19
712 1.4 riastrad *
713 1.4 riastrad * Verify that nextafterl and nexttowardl, which implement the
714 1.4 riastrad * nextUp and nextDown operations, obey this rule and don't
715 1.4 riastrad * send -0 to +0 or +0 to -0, respectively.
716 1.4 riastrad */
717 1.4 riastrad
718 1.4 riastrad CHECK(0, nextafterl, z_neg, +INFINITY, m);
719 1.4 riastrad CHECK(1, nexttowardl, z_neg, +INFINITY, m);
720 1.4 riastrad CHECK(2, nextafterl, z_pos, +INFINITY, m);
721 1.4 riastrad CHECK(3, nexttowardl, z_pos, +INFINITY, m);
722 1.4 riastrad
723 1.4 riastrad CHECK(4, nextafterl, z_pos, -INFINITY, -m);
724 1.4 riastrad CHECK(5, nexttowardl, z_pos, -INFINITY, -m);
725 1.4 riastrad CHECK(6, nextafterl, z_neg, -INFINITY, -m);
726 1.4 riastrad CHECK(7, nexttowardl, z_neg, -INFINITY, -m);
727 1.4 riastrad
728 1.4 riastrad /*
729 1.4 riastrad * `If x is the negative number of least magnitude in x's
730 1.4 riastrad * format, nextUp(x) is -0.'
731 1.4 riastrad * --IEEE 754-2019, 5.3.1 General operations, p. 19
732 1.4 riastrad */
733 1.4 riastrad CHECK(8, nextafterl, -m, +INFINITY, 0);
734 1.4 riastrad CHECK(9, nexttowardl, -m, +INFINITY, 0);
735 1.4 riastrad ATF_CHECK(signbit(nextafterl(-m, +INFINITY)) != 0);
736 1.4 riastrad CHECK(10, nextafterl, m, -INFINITY, 0);
737 1.4 riastrad CHECK(11, nexttowardl, m, -INFINITY, 0);
738 1.4 riastrad ATF_CHECK(signbit(nextafterl(m, -INFINITY)) == 0);
739 1.4 riastrad }
740 1.4 riastrad
741 1.4 riastrad ATF_TC(nextl_near_0);
742 1.4 riastrad ATF_TC_HEAD(nextl_near_0, tc)
743 1.4 riastrad {
744 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near 0");
745 1.4 riastrad }
746 1.4 riastrad ATF_TC_BODY(nextl_near_0, tc)
747 1.4 riastrad {
748 1.4 riastrad static const long double x[] = {
749 1.4 riastrad [0] = 0,
750 1.4 riastrad #ifdef __LDBL_HAS_DENORM__
751 1.4 riastrad [1] = __LDBL_DENORM_MIN__,
752 1.4 riastrad [2] = 2*__LDBL_DENORM_MIN__,
753 1.4 riastrad [3] = 3*__LDBL_DENORM_MIN__,
754 1.4 riastrad [4] = 4*__LDBL_DENORM_MIN__,
755 1.4 riastrad #else
756 1.4 riastrad [1] = LDBL_MIN,
757 1.4 riastrad [2] = LDBL_MIN*(1 + LDBL_EPSILON),
758 1.4 riastrad [3] = LDBL_MIN*(1 + 2*LDBL_EPSILON),
759 1.4 riastrad [4] = LDBL_MIN*(1 + 3*LDBL_EPSILON),
760 1.4 riastrad #endif
761 1.4 riastrad };
762 1.4 riastrad
763 1.4 riastrad checkl(x, __arraycount(x));
764 1.1 riastrad }
765 1.1 riastrad
766 1.4 riastrad ATF_TC(nextl_near_sub_normal);
767 1.4 riastrad ATF_TC_HEAD(nextl_near_sub_normal, tc)
768 1.1 riastrad {
769 1.4 riastrad atf_tc_set_md_var(tc, "descr",
770 1.4 riastrad "nextafterl/nexttowardl near the subnormal/normal boundary");
771 1.1 riastrad }
772 1.4 riastrad ATF_TC_BODY(nextl_near_sub_normal, tc)
773 1.1 riastrad {
774 1.4 riastrad #ifdef __LDBL_HAS_DENORM__
775 1.4 riastrad static const long double x[] = {
776 1.4 riastrad [0] = LDBL_MIN - 3*__LDBL_DENORM_MIN__,
777 1.4 riastrad [1] = LDBL_MIN - 2*__LDBL_DENORM_MIN__,
778 1.4 riastrad [2] = LDBL_MIN - __LDBL_DENORM_MIN__,
779 1.4 riastrad [3] = LDBL_MIN,
780 1.4 riastrad [4] = LDBL_MIN + __LDBL_DENORM_MIN__,
781 1.4 riastrad [5] = LDBL_MIN + 2*__LDBL_DENORM_MIN__,
782 1.4 riastrad [6] = LDBL_MIN + 3*__LDBL_DENORM_MIN__,
783 1.4 riastrad };
784 1.1 riastrad
785 1.4 riastrad checkl(x, __arraycount(x));
786 1.4 riastrad #else /* !__LDBL_HAS_DENORM__ */
787 1.4 riastrad atf_tc_skip("no subnormals on this architecture");
788 1.4 riastrad #endif /* !__LDBL_HAS_DENORM__ */
789 1.1 riastrad }
790 1.1 riastrad
791 1.4 riastrad ATF_TC(nextl_near_1);
792 1.4 riastrad ATF_TC_HEAD(nextl_near_1, tc)
793 1.1 riastrad {
794 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near 1");
795 1.1 riastrad }
796 1.4 riastrad ATF_TC_BODY(nextl_near_1, tc)
797 1.1 riastrad {
798 1.4 riastrad static const long double x[] = {
799 1.4 riastrad [0] = 1 - 3*LDBL_EPSILON/2,
800 1.4 riastrad [1] = 1 - 2*LDBL_EPSILON/2,
801 1.4 riastrad [2] = 1 - LDBL_EPSILON/2,
802 1.4 riastrad [3] = 1,
803 1.4 riastrad [4] = 1 + LDBL_EPSILON,
804 1.4 riastrad [5] = 1 + 2*LDBL_EPSILON,
805 1.4 riastrad [6] = 1 + 3*LDBL_EPSILON,
806 1.4 riastrad };
807 1.1 riastrad
808 1.4 riastrad checkl(x, __arraycount(x));
809 1.1 riastrad }
810 1.1 riastrad
811 1.4 riastrad ATF_TC(nextl_near_1_5);
812 1.4 riastrad ATF_TC_HEAD(nextl_near_1_5, tc)
813 1.1 riastrad {
814 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near 1.5");
815 1.1 riastrad }
816 1.4 riastrad ATF_TC_BODY(nextl_near_1_5, tc)
817 1.1 riastrad {
818 1.4 riastrad static const long double x[] = {
819 1.4 riastrad [0] = 1.5 - 3*LDBL_EPSILON,
820 1.4 riastrad [1] = 1.5 - 2*LDBL_EPSILON,
821 1.4 riastrad [2] = 1.5 - LDBL_EPSILON,
822 1.4 riastrad [3] = 1.5,
823 1.4 riastrad [4] = 1.5 + LDBL_EPSILON,
824 1.4 riastrad [5] = 1.5 + 2*LDBL_EPSILON,
825 1.4 riastrad [6] = 1.5 + 3*LDBL_EPSILON,
826 1.4 riastrad };
827 1.1 riastrad
828 1.4 riastrad checkl(x, __arraycount(x));
829 1.1 riastrad }
830 1.1 riastrad
831 1.4 riastrad ATF_TC(nextl_near_infinity);
832 1.4 riastrad ATF_TC_HEAD(nextl_near_infinity, tc)
833 1.1 riastrad {
834 1.4 riastrad atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near infinity");
835 1.1 riastrad }
836 1.4 riastrad ATF_TC_BODY(nextl_near_infinity, tc)
837 1.1 riastrad {
838 1.4 riastrad static const long double x[] = {
839 1.4 riastrad [0] = LDBL_MAX,
840 1.4 riastrad [1] = INFINITY,
841 1.4 riastrad };
842 1.4 riastrad volatile long double t;
843 1.4 riastrad
844 1.4 riastrad if (!isinf(INFINITY))
845 1.4 riastrad atf_tc_skip("no infinities on this architecture");
846 1.4 riastrad
847 1.4 riastrad checkl(x, __arraycount(x));
848 1.1 riastrad
849 1.4 riastrad ATF_CHECK_EQ_MSG((t = nextafterl(INFINITY, INFINITY)), INFINITY,
850 1.4 riastrad "t=%La=%Lg", t, t);
851 1.4 riastrad ATF_CHECK_EQ_MSG((t = nextafterl(-INFINITY, -INFINITY)), -INFINITY,
852 1.4 riastrad "t=%La=%Lg", t, t);
853 1.1 riastrad }
854 1.1 riastrad
855 1.2 riastrad #endif /* __vax__ */
856 1.2 riastrad
857 1.1 riastrad ATF_TP_ADD_TCS(tp)
858 1.1 riastrad {
859 1.1 riastrad
860 1.2 riastrad #ifdef __vax__
861 1.2 riastrad ATF_TP_ADD_TC(tp, vaxafter);
862 1.2 riastrad #else
863 1.4 riastrad ATF_TP_ADD_TC(tp, next_nan);
864 1.4 riastrad ATF_TP_ADD_TC(tp, next_near_0);
865 1.4 riastrad ATF_TP_ADD_TC(tp, next_near_1);
866 1.4 riastrad ATF_TP_ADD_TC(tp, next_near_1_5);
867 1.4 riastrad ATF_TP_ADD_TC(tp, next_near_infinity);
868 1.4 riastrad ATF_TP_ADD_TC(tp, next_near_sub_normal);
869 1.4 riastrad ATF_TP_ADD_TC(tp, next_signed_0);
870 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_nan);
871 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_near_0);
872 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_near_1);
873 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_near_1_5);
874 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_near_infinity);
875 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_near_sub_normal);
876 1.4 riastrad ATF_TP_ADD_TC(tp, nextf_signed_0);
877 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_nan);
878 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_near_0);
879 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_near_1);
880 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_near_1_5);
881 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_near_infinity);
882 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_near_sub_normal);
883 1.4 riastrad ATF_TP_ADD_TC(tp, nextl_signed_0);
884 1.2 riastrad #endif
885 1.1 riastrad return atf_no_error();
886 1.1 riastrad }
887