Home | History | Annotate | Line # | Download | only in libm
      1  1.8  riastrad /*	$NetBSD: t_next.c,v 1.8 2025/04/07 01:31:18 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.8  riastrad __RCSID("$NetBSD: t_next.c,v 1.8 2025/04/07 01:31:18 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.7  riastrad #ifdef __HAVE_LONG_DOUBLE
    114  1.4  riastrad 		if (isnormal(x[i])) {
    115  1.4  riastrad 			CHECK(i, nexttoward, x[i], x[i]*(1 - LDBL_EPSILON/2),
    116  1.4  riastrad 			    x[i - 1]);
    117  1.4  riastrad 		}
    118  1.7  riastrad #endif
    119  1.4  riastrad 
    120  1.4  riastrad 		CHECK(i, nextafter, x[i], x[i - 1], x[i - 1]);
    121  1.4  riastrad 		CHECK(i, nexttoward, x[i], x[i - 1], x[i - 1]);
    122  1.4  riastrad 		CHECK(i, nextafter, x[i], x[0], x[i - 1]);
    123  1.4  riastrad 		CHECK(i, nexttoward, x[i], x[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], -0., x[i - 1]);
    127  1.4  riastrad 		CHECK(i, nexttoward, x[i], -0., x[i - 1]);
    128  1.4  riastrad 		CHECK(i, nextafter, x[i], -x[0], x[i - 1]);
    129  1.4  riastrad 		CHECK(i, nexttoward, x[i], -x[0], x[i - 1]);
    130  1.4  riastrad 		CHECK(i, nextafter, x[i], -x[i], x[i - 1]);
    131  1.4  riastrad 		CHECK(i, nexttoward, x[i], -x[i], x[i - 1]);
    132  1.4  riastrad 		CHECK(i, nextafter, x[i], -INFINITY, x[i - 1]);
    133  1.4  riastrad 		CHECK(i, nexttoward, x[i], -INFINITY, x[i - 1]);
    134  1.4  riastrad 
    135  1.4  riastrad 		CHECK(i, nextafter, -x[i], -x[i - 1], -x[i - 1]);
    136  1.4  riastrad 		CHECK(i, nexttoward, -x[i], -x[i - 1], -x[i - 1]);
    137  1.4  riastrad 		CHECK(i, nextafter, -x[i], -x[0], -x[i - 1]);
    138  1.4  riastrad 		CHECK(i, nexttoward, -x[i], -x[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], +0., -x[i - 1]);
    142  1.4  riastrad 		CHECK(i, nexttoward, -x[i], +0., -x[i - 1]);
    143  1.4  riastrad 		CHECK(i, nextafter, -x[i], x[0], -x[i - 1]);
    144  1.4  riastrad 		CHECK(i, nexttoward, -x[i], x[0], -x[i - 1]);
    145  1.4  riastrad 		CHECK(i, nextafter, -x[i], INFINITY, -x[i - 1]);
    146  1.4  riastrad 		CHECK(i, nexttoward, -x[i], INFINITY, -x[i - 1]);
    147  1.4  riastrad 	}
    148  1.4  riastrad }
    149  1.4  riastrad 
    150  1.4  riastrad /*
    151  1.4  riastrad  * checkf(x, n)
    152  1.4  riastrad  *
    153  1.4  riastrad  *	x[0], x[1], ..., x[n - 1] are consecutive single floating-point
    154  1.4  riastrad  *	numbers.  Verify nextafterf and nexttowardf follow exactly this
    155  1.4  riastrad  *	sequence, forward and back, and in negative.
    156  1.4  riastrad  */
    157  1.4  riastrad static void
    158  1.4  riastrad checkf(const float *x, unsigned n)
    159  1.4  riastrad {
    160  1.4  riastrad 	unsigned i;
    161  1.4  riastrad 
    162  1.4  riastrad 	for (i = 0; i < n; 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 		CHECK(i, nextafterf, -x[i], -x[i], -x[i]);
    166  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], -x[i], -x[i]);
    167  1.4  riastrad 	}
    168  1.4  riastrad 
    169  1.4  riastrad 	for (i = 0; i < n - 1; i++) {
    170  1.4  riastrad 		ATF_REQUIRE_MSG(x[i] < x[i + 1], "i=%u", i);
    171  1.4  riastrad 
    172  1.4  riastrad 		if (isnormal(x[i])) {
    173  1.4  riastrad 			CHECK(i, nexttowardf, x[i], x[i]*(1 + LDBL_EPSILON),
    174  1.4  riastrad 			    x[i + 1]);
    175  1.4  riastrad 		}
    176  1.4  riastrad 
    177  1.4  riastrad 		CHECK(i, nextafterf, x[i], x[i + 1], x[i + 1]);
    178  1.4  riastrad 		CHECK(i, nexttowardf, x[i], x[i + 1], x[i + 1]);
    179  1.4  riastrad 		CHECK(i, nextafterf, x[i], x[n - 1], x[i + 1]);
    180  1.4  riastrad 		CHECK(i, nexttowardf, x[i], x[n - 1], x[i + 1]);
    181  1.4  riastrad 		CHECK(i, nextafterf, x[i], INFINITY, x[i + 1]);
    182  1.4  riastrad 		CHECK(i, nexttowardf, x[i], INFINITY, x[i + 1]);
    183  1.4  riastrad 
    184  1.4  riastrad 		CHECK(i, nextafterf, -x[i], -x[i + 1], -x[i + 1]);
    185  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], -x[i + 1], -x[i + 1]);
    186  1.4  riastrad 		CHECK(i, nextafterf, -x[i], -x[n - 1], -x[i + 1]);
    187  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], -x[n - 1], -x[i + 1]);
    188  1.4  riastrad 		CHECK(i, nextafterf, -x[i], -INFINITY, -x[i + 1]);
    189  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], -INFINITY, -x[i + 1]);
    190  1.4  riastrad 	}
    191  1.4  riastrad 
    192  1.4  riastrad 	for (i = n; i --> 1;) {
    193  1.4  riastrad 		ATF_REQUIRE_MSG(x[i - 1] < x[i], "i=%u", i);
    194  1.4  riastrad 
    195  1.4  riastrad 		if (isnormal(x[i])) {
    196  1.4  riastrad 			CHECK(i, nexttowardf, x[i], x[i]*(1 - LDBL_EPSILON/2),
    197  1.4  riastrad 			    x[i - 1]);
    198  1.4  riastrad 		}
    199  1.4  riastrad 
    200  1.4  riastrad 		CHECK(i, nextafterf, x[i], x[i - 1], x[i - 1]);
    201  1.4  riastrad 		CHECK(i, nexttowardf, x[i], x[i - 1], x[i - 1]);
    202  1.4  riastrad 		CHECK(i, nextafterf, x[i], x[0], x[i - 1]);
    203  1.4  riastrad 		CHECK(i, nexttowardf, x[i], x[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], -0., x[i - 1]);
    207  1.4  riastrad 		CHECK(i, nexttowardf, x[i], -0., x[i - 1]);
    208  1.4  riastrad 		CHECK(i, nextafterf, x[i], -x[0], x[i - 1]);
    209  1.4  riastrad 		CHECK(i, nexttowardf, x[i], -x[0], x[i - 1]);
    210  1.4  riastrad 		CHECK(i, nextafterf, x[i], -x[i], x[i - 1]);
    211  1.4  riastrad 		CHECK(i, nexttowardf, x[i], -x[i], x[i - 1]);
    212  1.4  riastrad 		CHECK(i, nextafterf, x[i], -INFINITY, x[i - 1]);
    213  1.4  riastrad 		CHECK(i, nexttowardf, x[i], -INFINITY, x[i - 1]);
    214  1.4  riastrad 
    215  1.4  riastrad 		CHECK(i, nextafterf, -x[i], -x[i - 1], -x[i - 1]);
    216  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], -x[i - 1], -x[i - 1]);
    217  1.4  riastrad 		CHECK(i, nextafterf, -x[i], -x[0], -x[i - 1]);
    218  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], -x[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], +0., -x[i - 1]);
    222  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], +0., -x[i - 1]);
    223  1.4  riastrad 		CHECK(i, nextafterf, -x[i], x[0], -x[i - 1]);
    224  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], x[0], -x[i - 1]);
    225  1.4  riastrad 		CHECK(i, nextafterf, -x[i], INFINITY, -x[i - 1]);
    226  1.4  riastrad 		CHECK(i, nexttowardf, -x[i], INFINITY, -x[i - 1]);
    227  1.4  riastrad 	}
    228  1.4  riastrad }
    229  1.4  riastrad 
    230  1.4  riastrad /*
    231  1.4  riastrad  * checkl(x, n)
    232  1.4  riastrad  *
    233  1.4  riastrad  *	x[0], x[1], ..., x[n - 1] are consecutive long double
    234  1.4  riastrad  *	floating-point numbers.  Verify nextafterl and nexttowardl
    235  1.4  riastrad  *	follow exactly this sequence, forward and back, and in
    236  1.4  riastrad  *	negative.
    237  1.4  riastrad  */
    238  1.4  riastrad static void
    239  1.4  riastrad checkl(const long double *x, unsigned n)
    240  1.4  riastrad {
    241  1.4  riastrad 	unsigned i;
    242  1.4  riastrad 
    243  1.4  riastrad 	for (i = 0; i < n; 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 		CHECK(i, nextafterl, -x[i], -x[i], -x[i]);
    247  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], -x[i], -x[i]);
    248  1.4  riastrad 	}
    249  1.4  riastrad 
    250  1.4  riastrad 	for (i = 0; i < n - 1; i++) {
    251  1.4  riastrad 		ATF_REQUIRE_MSG(x[i] < x[i + 1], "i=%u", i);
    252  1.4  riastrad 
    253  1.4  riastrad 		CHECK(i, nextafterl, x[i], x[i + 1], x[i + 1]);
    254  1.4  riastrad 		CHECK(i, nexttowardl, x[i], x[i + 1], x[i + 1]);
    255  1.4  riastrad 		CHECK(i, nextafterl, x[i], x[n - 1], x[i + 1]);
    256  1.4  riastrad 		CHECK(i, nexttowardl, x[i], x[n - 1], x[i + 1]);
    257  1.4  riastrad 		CHECK(i, nextafterl, x[i], INFINITY, x[i + 1]);
    258  1.4  riastrad 		CHECK(i, nexttowardl, x[i], INFINITY, x[i + 1]);
    259  1.4  riastrad 
    260  1.4  riastrad 		CHECK(i, nextafterl, -x[i], -x[i + 1], -x[i + 1]);
    261  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], -x[i + 1], -x[i + 1]);
    262  1.4  riastrad 		CHECK(i, nextafterl, -x[i], -x[n - 1], -x[i + 1]);
    263  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], -x[n - 1], -x[i + 1]);
    264  1.4  riastrad 		CHECK(i, nextafterl, -x[i], -INFINITY, -x[i + 1]);
    265  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], -INFINITY, -x[i + 1]);
    266  1.4  riastrad 	}
    267  1.4  riastrad 
    268  1.4  riastrad 	for (i = n; i --> 1;) {
    269  1.4  riastrad 		ATF_REQUIRE_MSG(x[i - 1] < x[i], "i=%u", i);
    270  1.4  riastrad 
    271  1.4  riastrad 		CHECK(i, nextafterl, x[i], x[i - 1], x[i - 1]);
    272  1.4  riastrad 		CHECK(i, nexttowardl, x[i], x[i - 1], x[i - 1]);
    273  1.4  riastrad 		CHECK(i, nextafterl, x[i], x[0], x[i - 1]);
    274  1.4  riastrad 		CHECK(i, nexttowardl, x[i], x[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], -0., x[i - 1]);
    278  1.4  riastrad 		CHECK(i, nexttowardl, x[i], -0., x[i - 1]);
    279  1.4  riastrad 		CHECK(i, nextafterl, x[i], -x[0], x[i - 1]);
    280  1.4  riastrad 		CHECK(i, nexttowardl, x[i], -x[0], x[i - 1]);
    281  1.4  riastrad 		CHECK(i, nextafterl, x[i], -x[i], x[i - 1]);
    282  1.4  riastrad 		CHECK(i, nexttowardl, x[i], -x[i], x[i - 1]);
    283  1.4  riastrad 		CHECK(i, nextafterl, x[i], -INFINITY, x[i - 1]);
    284  1.4  riastrad 		CHECK(i, nexttowardl, x[i], -INFINITY, x[i - 1]);
    285  1.4  riastrad 
    286  1.4  riastrad 		CHECK(i, nextafterl, -x[i], -x[i - 1], -x[i - 1]);
    287  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], -x[i - 1], -x[i - 1]);
    288  1.4  riastrad 		CHECK(i, nextafterl, -x[i], -x[0], -x[i - 1]);
    289  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], -x[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], +0., -x[i - 1]);
    293  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], +0., -x[i - 1]);
    294  1.4  riastrad 		CHECK(i, nextafterl, -x[i], x[0], -x[i - 1]);
    295  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], x[0], -x[i - 1]);
    296  1.4  riastrad 		CHECK(i, nextafterl, -x[i], INFINITY, -x[i - 1]);
    297  1.4  riastrad 		CHECK(i, nexttowardl, -x[i], INFINITY, -x[i - 1]);
    298  1.4  riastrad 	}
    299  1.4  riastrad }
    300  1.4  riastrad 
    301  1.4  riastrad ATF_TC(next_nan);
    302  1.4  riastrad ATF_TC_HEAD(next_nan, tc)
    303  1.4  riastrad {
    304  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward on NaN");
    305  1.4  riastrad }
    306  1.4  riastrad ATF_TC_BODY(next_nan, tc)
    307  1.4  riastrad {
    308  1.4  riastrad #ifdef NAN
    309  1.4  riastrad 	/* XXX verify the NaN is quiet */
    310  1.4  riastrad 	ATF_CHECK(isnan(nextafter(NAN, 0)));
    311  1.4  riastrad 	ATF_CHECK(isnan(nexttoward(NAN, 0)));
    312  1.4  riastrad 	ATF_CHECK(isnan(nextafter(0, NAN)));
    313  1.4  riastrad 	ATF_CHECK(isnan(nexttoward(0, NAN)));
    314  1.4  riastrad #else
    315  1.4  riastrad 	atf_tc_skip("no NaNs on this architecture");
    316  1.4  riastrad #endif
    317  1.4  riastrad }
    318  1.4  riastrad 
    319  1.4  riastrad ATF_TC(next_signed_0);
    320  1.4  riastrad ATF_TC_HEAD(next_signed_0, tc)
    321  1.4  riastrad {
    322  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward on signed 0");
    323  1.4  riastrad }
    324  1.4  riastrad ATF_TC_BODY(next_signed_0, tc)
    325  1.4  riastrad {
    326  1.4  riastrad 	volatile double z_pos = +0.;
    327  1.4  riastrad 	volatile double z_neg = -0.;
    328  1.8  riastrad #if __DBL_HAS_DENORM__
    329  1.4  riastrad 	volatile double m = __DBL_DENORM_MIN__;
    330  1.4  riastrad #else
    331  1.4  riastrad 	volatile double m = DBL_MIN;
    332  1.4  riastrad #endif
    333  1.4  riastrad 
    334  1.4  riastrad 	if (signbit(z_pos) == signbit(z_neg))
    335  1.4  riastrad 		atf_tc_skip("no signed zeroes on this architecture");
    336  1.4  riastrad 
    337  1.4  riastrad 	/*
    338  1.4  riastrad 	 * `nextUp(x) is the least floating-point number in the format
    339  1.4  riastrad 	 *  of x that compares greater than x. [...] nextDown(x) is
    340  1.4  riastrad 	 *  -nextUp(-x).'
    341  1.4  riastrad 	 * --IEEE 754-2019, 5.3.1 General operations, p. 19
    342  1.4  riastrad 	 *
    343  1.4  riastrad 	 * Verify that nextafter and nexttoward, which implement the
    344  1.4  riastrad 	 * nextUp and nextDown operations, obey this rule and don't
    345  1.4  riastrad 	 * send -0 to +0 or +0 to -0, respectively.
    346  1.4  riastrad 	 */
    347  1.4  riastrad 
    348  1.4  riastrad 	CHECK(0, nextafter, z_neg, +INFINITY, m);
    349  1.4  riastrad 	CHECK(1, nexttoward, z_neg, +INFINITY, m);
    350  1.4  riastrad 	CHECK(2, nextafter, z_pos, +INFINITY, m);
    351  1.4  riastrad 	CHECK(3, nexttoward, z_pos, +INFINITY, m);
    352  1.4  riastrad 
    353  1.4  riastrad 	CHECK(4, nextafter, z_pos, -INFINITY, -m);
    354  1.4  riastrad 	CHECK(5, nexttoward, z_pos, -INFINITY, -m);
    355  1.4  riastrad 	CHECK(6, nextafter, z_neg, -INFINITY, -m);
    356  1.4  riastrad 	CHECK(7, nexttoward, z_neg, -INFINITY, -m);
    357  1.4  riastrad 
    358  1.4  riastrad 	/*
    359  1.4  riastrad 	 * `If x is the negative number of least magnitude in x's
    360  1.4  riastrad 	 *  format, nextUp(x) is -0.'
    361  1.4  riastrad 	 * --IEEE 754-2019, 5.3.1 General operations, p. 19
    362  1.4  riastrad 	 *
    363  1.4  riastrad 	 * Verify that nextafter and nexttoward return the correctly
    364  1.4  riastrad 	 * signed zero.
    365  1.4  riastrad 	 */
    366  1.4  riastrad 	CHECK(8, nextafter, -m, +INFINITY, 0);
    367  1.4  riastrad 	CHECK(9, nexttoward, -m, +INFINITY, 0);
    368  1.4  riastrad 	ATF_CHECK(signbit(nextafter(-m, +INFINITY)) != 0);
    369  1.4  riastrad 	CHECK(10, nextafter, m, -INFINITY, 0);
    370  1.4  riastrad 	CHECK(11, nexttoward, m, -INFINITY, 0);
    371  1.4  riastrad 	ATF_CHECK(signbit(nextafter(m, -INFINITY)) == 0);
    372  1.4  riastrad }
    373  1.4  riastrad 
    374  1.4  riastrad ATF_TC(next_near_0);
    375  1.4  riastrad ATF_TC_HEAD(next_near_0, tc)
    376  1.4  riastrad {
    377  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near 0");
    378  1.4  riastrad }
    379  1.4  riastrad ATF_TC_BODY(next_near_0, tc)
    380  1.4  riastrad {
    381  1.4  riastrad 	static const double x[] = {
    382  1.4  riastrad 		[0] = 0,
    383  1.8  riastrad #if __DBL_HAS_DENORM__
    384  1.4  riastrad 		[1] = __DBL_DENORM_MIN__,
    385  1.4  riastrad 		[2] = 2*__DBL_DENORM_MIN__,
    386  1.4  riastrad 		[3] = 3*__DBL_DENORM_MIN__,
    387  1.4  riastrad 		[4] = 4*__DBL_DENORM_MIN__,
    388  1.4  riastrad #else
    389  1.4  riastrad 		[1] = DBL_MIN,
    390  1.4  riastrad 		[2] = DBL_MIN*(1 + DBL_EPSILON),
    391  1.4  riastrad 		[3] = DBL_MIN*(1 + 2*DBL_EPSILON),
    392  1.4  riastrad 		[4] = DBL_MIN*(1 + 3*DBL_EPSILON),
    393  1.4  riastrad #endif
    394  1.4  riastrad 	};
    395  1.4  riastrad 
    396  1.4  riastrad 	check(x, __arraycount(x));
    397  1.4  riastrad }
    398  1.4  riastrad 
    399  1.4  riastrad ATF_TC(next_near_sub_normal);
    400  1.4  riastrad ATF_TC_HEAD(next_near_sub_normal, tc)
    401  1.4  riastrad {
    402  1.4  riastrad 	atf_tc_set_md_var(tc, "descr",
    403  1.4  riastrad 	    "nextafter/nexttoward near the subnormal/normal boundary");
    404  1.4  riastrad }
    405  1.4  riastrad ATF_TC_BODY(next_near_sub_normal, tc)
    406  1.4  riastrad {
    407  1.8  riastrad #if __DBL_HAS_DENORM__
    408  1.4  riastrad 	static const double x[] = {
    409  1.4  riastrad 		[0] = DBL_MIN - 3*__DBL_DENORM_MIN__,
    410  1.4  riastrad 		[1] = DBL_MIN - 2*__DBL_DENORM_MIN__,
    411  1.4  riastrad 		[2] = DBL_MIN - __DBL_DENORM_MIN__,
    412  1.4  riastrad 		[3] = DBL_MIN,
    413  1.4  riastrad 		[4] = DBL_MIN + __DBL_DENORM_MIN__,
    414  1.4  riastrad 		[5] = DBL_MIN + 2*__DBL_DENORM_MIN__,
    415  1.4  riastrad 		[6] = DBL_MIN + 3*__DBL_DENORM_MIN__,
    416  1.4  riastrad 	};
    417  1.4  riastrad 
    418  1.4  riastrad 	check(x, __arraycount(x));
    419  1.4  riastrad #else  /* !__DBL_HAS_DENORM__ */
    420  1.4  riastrad 	atf_tc_skip("no subnormals on this architecture");
    421  1.4  riastrad #endif	/* !__DBL_HAS_DENORM__ */
    422  1.4  riastrad }
    423  1.4  riastrad 
    424  1.4  riastrad ATF_TC(next_near_1);
    425  1.4  riastrad ATF_TC_HEAD(next_near_1, tc)
    426  1.4  riastrad {
    427  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near 1");
    428  1.4  riastrad }
    429  1.4  riastrad ATF_TC_BODY(next_near_1, tc)
    430  1.4  riastrad {
    431  1.4  riastrad 	static const double x[] = {
    432  1.4  riastrad 		[0] = 1 - 3*DBL_EPSILON/2,
    433  1.4  riastrad 		[1] = 1 - 2*DBL_EPSILON/2,
    434  1.4  riastrad 		[2] = 1 - DBL_EPSILON/2,
    435  1.4  riastrad 		[3] = 1,
    436  1.4  riastrad 		[4] = 1 + DBL_EPSILON,
    437  1.4  riastrad 		[5] = 1 + 2*DBL_EPSILON,
    438  1.4  riastrad 		[6] = 1 + 3*DBL_EPSILON,
    439  1.4  riastrad 	};
    440  1.4  riastrad 
    441  1.4  riastrad 	check(x, __arraycount(x));
    442  1.4  riastrad }
    443  1.4  riastrad 
    444  1.4  riastrad ATF_TC(next_near_1_5);
    445  1.4  riastrad ATF_TC_HEAD(next_near_1_5, tc)
    446  1.4  riastrad {
    447  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near 1.5");
    448  1.4  riastrad }
    449  1.4  riastrad ATF_TC_BODY(next_near_1_5, tc)
    450  1.4  riastrad {
    451  1.4  riastrad 	static const double x[] = {
    452  1.4  riastrad 		[0] = 1.5 - 3*DBL_EPSILON,
    453  1.4  riastrad 		[1] = 1.5 - 2*DBL_EPSILON,
    454  1.4  riastrad 		[2] = 1.5 - DBL_EPSILON,
    455  1.4  riastrad 		[3] = 1.5,
    456  1.4  riastrad 		[4] = 1.5 + DBL_EPSILON,
    457  1.4  riastrad 		[5] = 1.5 + 2*DBL_EPSILON,
    458  1.4  riastrad 		[6] = 1.5 + 3*DBL_EPSILON,
    459  1.4  riastrad 	};
    460  1.4  riastrad 
    461  1.4  riastrad 	check(x, __arraycount(x));
    462  1.4  riastrad }
    463  1.4  riastrad 
    464  1.4  riastrad ATF_TC(next_near_infinity);
    465  1.4  riastrad ATF_TC_HEAD(next_near_infinity, tc)
    466  1.4  riastrad {
    467  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter/nexttoward near infinity");
    468  1.4  riastrad }
    469  1.4  riastrad ATF_TC_BODY(next_near_infinity, tc)
    470  1.4  riastrad {
    471  1.4  riastrad 	static const double x[] = {
    472  1.4  riastrad 		[0] = DBL_MAX,
    473  1.4  riastrad 		[1] = INFINITY,
    474  1.4  riastrad 	};
    475  1.4  riastrad 	volatile double t;
    476  1.4  riastrad 
    477  1.4  riastrad 	if (!isinf(INFINITY))
    478  1.4  riastrad 		atf_tc_skip("no infinities on this architecture");
    479  1.4  riastrad 
    480  1.4  riastrad 	check(x, __arraycount(x));
    481  1.4  riastrad 
    482  1.4  riastrad 	ATF_CHECK_EQ_MSG((t = nextafter(INFINITY, INFINITY)), INFINITY,
    483  1.4  riastrad 	    "t=%a=%g", t, t);
    484  1.4  riastrad 	ATF_CHECK_EQ_MSG((t = nextafter(-INFINITY, -INFINITY)), -INFINITY,
    485  1.4  riastrad 	    "t=%a=%g", t, t);
    486  1.4  riastrad }
    487  1.4  riastrad 
    488  1.4  riastrad ATF_TC(nextf_nan);
    489  1.4  riastrad ATF_TC_HEAD(nextf_nan, tc)
    490  1.4  riastrad {
    491  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf on NaN");
    492  1.4  riastrad }
    493  1.4  riastrad ATF_TC_BODY(nextf_nan, tc)
    494  1.4  riastrad {
    495  1.4  riastrad #ifdef NAN
    496  1.4  riastrad 	/* XXX verify the NaN is quiet */
    497  1.4  riastrad 	ATF_CHECK(isnan(nextafterf(NAN, 0)));
    498  1.4  riastrad 	ATF_CHECK(isnan(nexttowardf(NAN, 0)));
    499  1.4  riastrad 	ATF_CHECK(isnan(nextafterf(0, NAN)));
    500  1.4  riastrad 	ATF_CHECK(isnan(nexttowardf(0, NAN)));
    501  1.4  riastrad #else
    502  1.4  riastrad 	atf_tc_skip("no NaNs on this architecture");
    503  1.4  riastrad #endif
    504  1.4  riastrad }
    505  1.4  riastrad 
    506  1.4  riastrad ATF_TC(nextf_signed_0);
    507  1.4  riastrad ATF_TC_HEAD(nextf_signed_0, tc)
    508  1.4  riastrad {
    509  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf on signed 0");
    510  1.4  riastrad }
    511  1.4  riastrad ATF_TC_BODY(nextf_signed_0, tc)
    512  1.4  riastrad {
    513  1.4  riastrad 	volatile float z_pos = +0.;
    514  1.4  riastrad 	volatile float z_neg = -0.;
    515  1.8  riastrad #if __FLT_HAS_DENORM__
    516  1.4  riastrad 	volatile float m = __FLT_DENORM_MIN__;
    517  1.4  riastrad #else
    518  1.4  riastrad 	volatile float m = FLT_MIN;
    519  1.4  riastrad #endif
    520  1.4  riastrad 
    521  1.4  riastrad 	if (signbit(z_pos) == signbit(z_neg))
    522  1.4  riastrad 		atf_tc_skip("no signed zeroes on this architecture");
    523  1.4  riastrad 
    524  1.4  riastrad 	/*
    525  1.4  riastrad 	 * `nextUp(x) is the least floating-point number in the format
    526  1.4  riastrad 	 *  of x that compares greater than x. [...] nextDown(x) is
    527  1.4  riastrad 	 *  -nextUp(-x).'
    528  1.4  riastrad 	 * --IEEE 754-2019, 5.3.1 General operations, p. 19
    529  1.4  riastrad 	 *
    530  1.4  riastrad 	 * Verify that nextafterf and nexttowardf, which implement the
    531  1.4  riastrad 	 * nextUp and nextDown operations, obey this rule and don't
    532  1.4  riastrad 	 * send -0 to +0 or +0 to -0, respectively.
    533  1.4  riastrad 	 */
    534  1.4  riastrad 
    535  1.4  riastrad 	CHECK(0, nextafterf, z_neg, +INFINITY, m);
    536  1.4  riastrad 	CHECK(1, nexttowardf, z_neg, +INFINITY, m);
    537  1.4  riastrad 	CHECK(2, nextafterf, z_pos, +INFINITY, m);
    538  1.4  riastrad 	CHECK(3, nexttowardf, z_pos, +INFINITY, m);
    539  1.4  riastrad 
    540  1.4  riastrad 	CHECK(4, nextafterf, z_pos, -INFINITY, -m);
    541  1.4  riastrad 	CHECK(5, nexttowardf, z_pos, -INFINITY, -m);
    542  1.4  riastrad 	CHECK(6, nextafterf, z_neg, -INFINITY, -m);
    543  1.4  riastrad 	CHECK(7, nexttowardf, z_neg, -INFINITY, -m);
    544  1.4  riastrad 
    545  1.4  riastrad 	/*
    546  1.4  riastrad 	 * `If x is the negative number of least magnitude in x's
    547  1.4  riastrad 	 *  format, nextUp(x) is -0.'
    548  1.4  riastrad 	 * --IEEE 754-2019, 5.3.1 General operations, p. 19
    549  1.4  riastrad 	 */
    550  1.4  riastrad 	CHECK(8, nextafterf, -m, +INFINITY, 0);
    551  1.4  riastrad 	CHECK(9, nexttowardf, -m, +INFINITY, 0);
    552  1.4  riastrad 	ATF_CHECK(signbit(nextafterf(-m, +INFINITY)) != 0);
    553  1.4  riastrad 	CHECK(10, nextafterf, m, -INFINITY, 0);
    554  1.4  riastrad 	CHECK(11, nexttowardf, m, -INFINITY, 0);
    555  1.4  riastrad 	ATF_CHECK(signbit(nextafterf(m, -INFINITY)) == 0);
    556  1.4  riastrad }
    557  1.4  riastrad 
    558  1.4  riastrad ATF_TC(nextf_near_0);
    559  1.4  riastrad ATF_TC_HEAD(nextf_near_0, tc)
    560  1.4  riastrad {
    561  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near 0");
    562  1.4  riastrad }
    563  1.4  riastrad ATF_TC_BODY(nextf_near_0, tc)
    564  1.4  riastrad {
    565  1.4  riastrad 	static const float x[] = {
    566  1.4  riastrad 		[0] = 0,
    567  1.8  riastrad #if __FLT_HAS_DENORM__
    568  1.4  riastrad 		[1] = __FLT_DENORM_MIN__,
    569  1.4  riastrad 		[2] = 2*__FLT_DENORM_MIN__,
    570  1.4  riastrad 		[3] = 3*__FLT_DENORM_MIN__,
    571  1.4  riastrad 		[4] = 4*__FLT_DENORM_MIN__,
    572  1.4  riastrad #else
    573  1.4  riastrad 		[1] = FLT_MIN,
    574  1.4  riastrad 		[2] = FLT_MIN*(1 + FLT_EPSILON),
    575  1.4  riastrad 		[3] = FLT_MIN*(1 + 2*FLT_EPSILON),
    576  1.4  riastrad 		[4] = FLT_MIN*(1 + 3*FLT_EPSILON),
    577  1.4  riastrad #endif
    578  1.4  riastrad 	};
    579  1.4  riastrad 
    580  1.4  riastrad 	checkf(x, __arraycount(x));
    581  1.4  riastrad }
    582  1.4  riastrad 
    583  1.4  riastrad ATF_TC(nextf_near_sub_normal);
    584  1.4  riastrad ATF_TC_HEAD(nextf_near_sub_normal, tc)
    585  1.4  riastrad {
    586  1.4  riastrad 	atf_tc_set_md_var(tc, "descr",
    587  1.4  riastrad 	    "nextafterf/nexttowardf near the subnormal/normal boundary");
    588  1.4  riastrad }
    589  1.4  riastrad ATF_TC_BODY(nextf_near_sub_normal, tc)
    590  1.4  riastrad {
    591  1.8  riastrad #if __FLT_HAS_DENORM__
    592  1.4  riastrad 	static const float x[] = {
    593  1.4  riastrad 		[0] = FLT_MIN - 3*__FLT_DENORM_MIN__,
    594  1.4  riastrad 		[1] = FLT_MIN - 2*__FLT_DENORM_MIN__,
    595  1.4  riastrad 		[2] = FLT_MIN - __FLT_DENORM_MIN__,
    596  1.4  riastrad 		[3] = FLT_MIN,
    597  1.4  riastrad 		[4] = FLT_MIN + __FLT_DENORM_MIN__,
    598  1.4  riastrad 		[5] = FLT_MIN + 2*__FLT_DENORM_MIN__,
    599  1.4  riastrad 		[6] = FLT_MIN + 3*__FLT_DENORM_MIN__,
    600  1.4  riastrad 	};
    601  1.4  riastrad 
    602  1.4  riastrad 	checkf(x, __arraycount(x));
    603  1.4  riastrad #else  /* !__FLT_HAS_DENORM__ */
    604  1.4  riastrad 	atf_tc_skip("no subnormals on this architecture");
    605  1.4  riastrad #endif	/* !__FLT_HAS_DENORM__ */
    606  1.4  riastrad }
    607  1.4  riastrad 
    608  1.4  riastrad ATF_TC(nextf_near_1);
    609  1.4  riastrad ATF_TC_HEAD(nextf_near_1, tc)
    610  1.4  riastrad {
    611  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near 1");
    612  1.4  riastrad }
    613  1.4  riastrad ATF_TC_BODY(nextf_near_1, tc)
    614  1.4  riastrad {
    615  1.4  riastrad 	static const float x[] = {
    616  1.4  riastrad 		[0] = 1 - 3*FLT_EPSILON/2,
    617  1.4  riastrad 		[1] = 1 - 2*FLT_EPSILON/2,
    618  1.4  riastrad 		[2] = 1 - FLT_EPSILON/2,
    619  1.4  riastrad 		[3] = 1,
    620  1.4  riastrad 		[4] = 1 + FLT_EPSILON,
    621  1.4  riastrad 		[5] = 1 + 2*FLT_EPSILON,
    622  1.4  riastrad 		[6] = 1 + 3*FLT_EPSILON,
    623  1.4  riastrad 	};
    624  1.4  riastrad 
    625  1.4  riastrad 	checkf(x, __arraycount(x));
    626  1.4  riastrad }
    627  1.4  riastrad 
    628  1.4  riastrad ATF_TC(nextf_near_1_5);
    629  1.4  riastrad ATF_TC_HEAD(nextf_near_1_5, tc)
    630  1.4  riastrad {
    631  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near 1.5");
    632  1.4  riastrad }
    633  1.4  riastrad ATF_TC_BODY(nextf_near_1_5, tc)
    634  1.1  riastrad {
    635  1.4  riastrad 	static const float x[] = {
    636  1.4  riastrad 		[0] = 1.5 - 3*FLT_EPSILON,
    637  1.4  riastrad 		[1] = 1.5 - 2*FLT_EPSILON,
    638  1.4  riastrad 		[2] = 1.5 - FLT_EPSILON,
    639  1.4  riastrad 		[3] = 1.5,
    640  1.4  riastrad 		[4] = 1.5 + FLT_EPSILON,
    641  1.4  riastrad 		[5] = 1.5 + 2*FLT_EPSILON,
    642  1.4  riastrad 		[6] = 1.5 + 3*FLT_EPSILON,
    643  1.4  riastrad 	};
    644  1.4  riastrad 
    645  1.4  riastrad 	checkf(x, __arraycount(x));
    646  1.4  riastrad }
    647  1.4  riastrad 
    648  1.4  riastrad ATF_TC(nextf_near_infinity);
    649  1.4  riastrad ATF_TC_HEAD(nextf_near_infinity, tc)
    650  1.4  riastrad {
    651  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf/nexttowardf near infinity");
    652  1.1  riastrad }
    653  1.4  riastrad ATF_TC_BODY(nextf_near_infinity, tc)
    654  1.1  riastrad {
    655  1.4  riastrad 	static const float x[] = {
    656  1.4  riastrad 		[0] = FLT_MAX,
    657  1.4  riastrad 		[1] = INFINITY,
    658  1.4  riastrad 	};
    659  1.4  riastrad 	volatile float t;
    660  1.4  riastrad 
    661  1.4  riastrad 	if (!isinf(INFINITY))
    662  1.4  riastrad 		atf_tc_skip("no infinities on this architecture");
    663  1.4  riastrad 
    664  1.4  riastrad 	checkf(x, __arraycount(x));
    665  1.4  riastrad 
    666  1.4  riastrad 	ATF_CHECK_EQ_MSG((t = nextafterf(INFINITY, INFINITY)), INFINITY,
    667  1.4  riastrad 	    "t=%a=%g", t, t);
    668  1.4  riastrad 	ATF_CHECK_EQ_MSG((t = nextafterf(-INFINITY, -INFINITY)), -INFINITY,
    669  1.4  riastrad 	    "t=%a=%g", t, t);
    670  1.4  riastrad }
    671  1.1  riastrad 
    672  1.4  riastrad ATF_TC(nextl_nan);
    673  1.4  riastrad ATF_TC_HEAD(nextl_nan, tc)
    674  1.4  riastrad {
    675  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl on NaN");
    676  1.4  riastrad }
    677  1.4  riastrad ATF_TC_BODY(nextl_nan, tc)
    678  1.4  riastrad {
    679  1.4  riastrad #ifdef NAN
    680  1.4  riastrad 	/* XXX verify the NaN is quiet */
    681  1.4  riastrad 	ATF_CHECK(isnan(nextafterl(NAN, 0)));
    682  1.4  riastrad 	ATF_CHECK(isnan(nexttowardl(NAN, 0)));
    683  1.4  riastrad 	ATF_CHECK(isnan(nextafterl(0, NAN)));
    684  1.4  riastrad 	ATF_CHECK(isnan(nexttowardl(0, NAN)));
    685  1.4  riastrad #else
    686  1.4  riastrad 	atf_tc_skip("no NaNs on this architecture");
    687  1.4  riastrad #endif
    688  1.1  riastrad }
    689  1.1  riastrad 
    690  1.4  riastrad ATF_TC(nextl_signed_0);
    691  1.4  riastrad ATF_TC_HEAD(nextl_signed_0, tc)
    692  1.1  riastrad {
    693  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl on signed 0");
    694  1.1  riastrad }
    695  1.4  riastrad ATF_TC_BODY(nextl_signed_0, tc)
    696  1.1  riastrad {
    697  1.4  riastrad 	volatile long double z_pos = +0.;
    698  1.4  riastrad 	volatile long double z_neg = -0.;
    699  1.8  riastrad #if __LDBL_HAS_DENORM__
    700  1.4  riastrad 	volatile long double m = __LDBL_DENORM_MIN__;
    701  1.4  riastrad #else
    702  1.4  riastrad 	volatile long double m = LDBL_MIN;
    703  1.4  riastrad #endif
    704  1.4  riastrad 
    705  1.4  riastrad 	if (signbit(z_pos) == signbit(z_neg))
    706  1.4  riastrad 		atf_tc_skip("no signed zeroes on this architecture");
    707  1.1  riastrad 
    708  1.4  riastrad 	/*
    709  1.4  riastrad 	 * `nextUp(x) is the least floating-point number in the format
    710  1.4  riastrad 	 *  of x that compares greater than x. [...] nextDown(x) is
    711  1.4  riastrad 	 *  -nextUp(-x).'
    712  1.4  riastrad 	 * --IEEE 754-2019, 5.3.1 General operations, p. 19
    713  1.4  riastrad 	 *
    714  1.4  riastrad 	 * Verify that nextafterl and nexttowardl, which implement the
    715  1.4  riastrad 	 * nextUp and nextDown operations, obey this rule and don't
    716  1.4  riastrad 	 * send -0 to +0 or +0 to -0, respectively.
    717  1.4  riastrad 	 */
    718  1.4  riastrad 
    719  1.4  riastrad 	CHECK(0, nextafterl, z_neg, +INFINITY, m);
    720  1.4  riastrad 	CHECK(1, nexttowardl, z_neg, +INFINITY, m);
    721  1.4  riastrad 	CHECK(2, nextafterl, z_pos, +INFINITY, m);
    722  1.4  riastrad 	CHECK(3, nexttowardl, z_pos, +INFINITY, m);
    723  1.4  riastrad 
    724  1.4  riastrad 	CHECK(4, nextafterl, z_pos, -INFINITY, -m);
    725  1.4  riastrad 	CHECK(5, nexttowardl, z_pos, -INFINITY, -m);
    726  1.4  riastrad 	CHECK(6, nextafterl, z_neg, -INFINITY, -m);
    727  1.4  riastrad 	CHECK(7, nexttowardl, z_neg, -INFINITY, -m);
    728  1.4  riastrad 
    729  1.4  riastrad 	/*
    730  1.4  riastrad 	 * `If x is the negative number of least magnitude in x's
    731  1.4  riastrad 	 *  format, nextUp(x) is -0.'
    732  1.4  riastrad 	 * --IEEE 754-2019, 5.3.1 General operations, p. 19
    733  1.4  riastrad 	 */
    734  1.4  riastrad 	CHECK(8, nextafterl, -m, +INFINITY, 0);
    735  1.4  riastrad 	CHECK(9, nexttowardl, -m, +INFINITY, 0);
    736  1.4  riastrad 	ATF_CHECK(signbit(nextafterl(-m, +INFINITY)) != 0);
    737  1.4  riastrad 	CHECK(10, nextafterl, m, -INFINITY, 0);
    738  1.4  riastrad 	CHECK(11, nexttowardl, m, -INFINITY, 0);
    739  1.4  riastrad 	ATF_CHECK(signbit(nextafterl(m, -INFINITY)) == 0);
    740  1.4  riastrad }
    741  1.4  riastrad 
    742  1.4  riastrad ATF_TC(nextl_near_0);
    743  1.4  riastrad ATF_TC_HEAD(nextl_near_0, tc)
    744  1.4  riastrad {
    745  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near 0");
    746  1.4  riastrad }
    747  1.4  riastrad ATF_TC_BODY(nextl_near_0, tc)
    748  1.4  riastrad {
    749  1.4  riastrad 	static const long double x[] = {
    750  1.4  riastrad 		[0] = 0,
    751  1.8  riastrad #if __LDBL_HAS_DENORM__
    752  1.4  riastrad 		[1] = __LDBL_DENORM_MIN__,
    753  1.4  riastrad 		[2] = 2*__LDBL_DENORM_MIN__,
    754  1.4  riastrad 		[3] = 3*__LDBL_DENORM_MIN__,
    755  1.4  riastrad 		[4] = 4*__LDBL_DENORM_MIN__,
    756  1.4  riastrad #else
    757  1.4  riastrad 		[1] = LDBL_MIN,
    758  1.4  riastrad 		[2] = LDBL_MIN*(1 + LDBL_EPSILON),
    759  1.4  riastrad 		[3] = LDBL_MIN*(1 + 2*LDBL_EPSILON),
    760  1.4  riastrad 		[4] = LDBL_MIN*(1 + 3*LDBL_EPSILON),
    761  1.4  riastrad #endif
    762  1.4  riastrad 	};
    763  1.4  riastrad 
    764  1.4  riastrad 	checkl(x, __arraycount(x));
    765  1.1  riastrad }
    766  1.1  riastrad 
    767  1.4  riastrad ATF_TC(nextl_near_sub_normal);
    768  1.4  riastrad ATF_TC_HEAD(nextl_near_sub_normal, tc)
    769  1.1  riastrad {
    770  1.4  riastrad 	atf_tc_set_md_var(tc, "descr",
    771  1.4  riastrad 	    "nextafterl/nexttowardl near the subnormal/normal boundary");
    772  1.1  riastrad }
    773  1.4  riastrad ATF_TC_BODY(nextl_near_sub_normal, tc)
    774  1.1  riastrad {
    775  1.8  riastrad #if __LDBL_HAS_DENORM__
    776  1.4  riastrad 	static const long double x[] = {
    777  1.4  riastrad 		[0] = LDBL_MIN - 3*__LDBL_DENORM_MIN__,
    778  1.4  riastrad 		[1] = LDBL_MIN - 2*__LDBL_DENORM_MIN__,
    779  1.4  riastrad 		[2] = LDBL_MIN - __LDBL_DENORM_MIN__,
    780  1.4  riastrad 		[3] = LDBL_MIN,
    781  1.4  riastrad 		[4] = LDBL_MIN + __LDBL_DENORM_MIN__,
    782  1.4  riastrad 		[5] = LDBL_MIN + 2*__LDBL_DENORM_MIN__,
    783  1.4  riastrad 		[6] = LDBL_MIN + 3*__LDBL_DENORM_MIN__,
    784  1.4  riastrad 	};
    785  1.1  riastrad 
    786  1.4  riastrad 	checkl(x, __arraycount(x));
    787  1.4  riastrad #else  /* !__LDBL_HAS_DENORM__ */
    788  1.4  riastrad 	atf_tc_skip("no subnormals on this architecture");
    789  1.4  riastrad #endif	/* !__LDBL_HAS_DENORM__ */
    790  1.1  riastrad }
    791  1.1  riastrad 
    792  1.4  riastrad ATF_TC(nextl_near_1);
    793  1.4  riastrad ATF_TC_HEAD(nextl_near_1, tc)
    794  1.1  riastrad {
    795  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near 1");
    796  1.1  riastrad }
    797  1.4  riastrad ATF_TC_BODY(nextl_near_1, tc)
    798  1.1  riastrad {
    799  1.4  riastrad 	static const long double x[] = {
    800  1.4  riastrad 		[0] = 1 - 3*LDBL_EPSILON/2,
    801  1.4  riastrad 		[1] = 1 - 2*LDBL_EPSILON/2,
    802  1.4  riastrad 		[2] = 1 - LDBL_EPSILON/2,
    803  1.4  riastrad 		[3] = 1,
    804  1.4  riastrad 		[4] = 1 + LDBL_EPSILON,
    805  1.4  riastrad 		[5] = 1 + 2*LDBL_EPSILON,
    806  1.4  riastrad 		[6] = 1 + 3*LDBL_EPSILON,
    807  1.4  riastrad 	};
    808  1.1  riastrad 
    809  1.4  riastrad 	checkl(x, __arraycount(x));
    810  1.1  riastrad }
    811  1.1  riastrad 
    812  1.4  riastrad ATF_TC(nextl_near_1_5);
    813  1.4  riastrad ATF_TC_HEAD(nextl_near_1_5, tc)
    814  1.1  riastrad {
    815  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near 1.5");
    816  1.1  riastrad }
    817  1.4  riastrad ATF_TC_BODY(nextl_near_1_5, tc)
    818  1.1  riastrad {
    819  1.4  riastrad 	static const long double x[] = {
    820  1.4  riastrad 		[0] = 1.5 - 3*LDBL_EPSILON,
    821  1.4  riastrad 		[1] = 1.5 - 2*LDBL_EPSILON,
    822  1.4  riastrad 		[2] = 1.5 - LDBL_EPSILON,
    823  1.4  riastrad 		[3] = 1.5,
    824  1.4  riastrad 		[4] = 1.5 + LDBL_EPSILON,
    825  1.4  riastrad 		[5] = 1.5 + 2*LDBL_EPSILON,
    826  1.4  riastrad 		[6] = 1.5 + 3*LDBL_EPSILON,
    827  1.4  riastrad 	};
    828  1.1  riastrad 
    829  1.4  riastrad 	checkl(x, __arraycount(x));
    830  1.1  riastrad }
    831  1.1  riastrad 
    832  1.4  riastrad ATF_TC(nextl_near_infinity);
    833  1.4  riastrad ATF_TC_HEAD(nextl_near_infinity, tc)
    834  1.1  riastrad {
    835  1.4  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl/nexttowardl near infinity");
    836  1.1  riastrad }
    837  1.4  riastrad ATF_TC_BODY(nextl_near_infinity, tc)
    838  1.1  riastrad {
    839  1.4  riastrad 	static const long double x[] = {
    840  1.4  riastrad 		[0] = LDBL_MAX,
    841  1.4  riastrad 		[1] = INFINITY,
    842  1.4  riastrad 	};
    843  1.4  riastrad 	volatile long double t;
    844  1.4  riastrad 
    845  1.4  riastrad 	if (!isinf(INFINITY))
    846  1.4  riastrad 		atf_tc_skip("no infinities on this architecture");
    847  1.4  riastrad 
    848  1.4  riastrad 	checkl(x, __arraycount(x));
    849  1.1  riastrad 
    850  1.4  riastrad 	ATF_CHECK_EQ_MSG((t = nextafterl(INFINITY, INFINITY)), INFINITY,
    851  1.4  riastrad 	    "t=%La=%Lg", t, t);
    852  1.4  riastrad 	ATF_CHECK_EQ_MSG((t = nextafterl(-INFINITY, -INFINITY)), -INFINITY,
    853  1.4  riastrad 	    "t=%La=%Lg", t, t);
    854  1.1  riastrad }
    855  1.1  riastrad 
    856  1.2  riastrad #endif	/* __vax__ */
    857  1.2  riastrad 
    858  1.1  riastrad ATF_TP_ADD_TCS(tp)
    859  1.1  riastrad {
    860  1.1  riastrad 
    861  1.2  riastrad #ifdef __vax__
    862  1.2  riastrad 	ATF_TP_ADD_TC(tp, vaxafter);
    863  1.2  riastrad #else
    864  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_nan);
    865  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_near_0);
    866  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_near_1);
    867  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_near_1_5);
    868  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_near_infinity);
    869  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_near_sub_normal);
    870  1.4  riastrad 	ATF_TP_ADD_TC(tp, next_signed_0);
    871  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_nan);
    872  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_near_0);
    873  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_near_1);
    874  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_near_1_5);
    875  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_near_infinity);
    876  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_near_sub_normal);
    877  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextf_signed_0);
    878  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_nan);
    879  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_near_0);
    880  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_near_1);
    881  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_near_1_5);
    882  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_near_infinity);
    883  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_near_sub_normal);
    884  1.4  riastrad 	ATF_TP_ADD_TC(tp, nextl_signed_0);
    885  1.2  riastrad #endif
    886  1.1  riastrad 	return atf_no_error();
    887  1.1  riastrad }
    888