Home | History | Annotate | Line # | Download | only in libm
t_next.c revision 1.2
      1  1.2  riastrad /*	$NetBSD: t_next.c,v 1.2 2024/05/05 14:29:38 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.2  riastrad __RCSID("$NetBSD: t_next.c,v 1.2 2024/05/05 14:29:38 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.2  riastrad ATF_TC(vaxafter)
     39  1.2  riastrad ATF_TC_HEAD(vaxafter, tc)
     40  1.2  riastrad {
     41  1.2  riastrad 
     42  1.2  riastrad 	atf_expect_fail("PR 57881: vax libm is missing various symbols")
     43  1.2  riastrad 	atf_tc_fail("missing nextafter{,f,l} and nexttoward{,f,l} on vax");
     44  1.2  riastrad }
     45  1.2  riastrad 
     46  1.2  riastrad #else  /* !__vax__ */
     47  1.2  riastrad 
     48  1.1  riastrad #define	CHECK(x, y)							      \
     49  1.1  riastrad 	ATF_CHECK_EQ_MSG((x), (y), #x"=%La=%Lg, "#y"=%La=%Lg",		      \
     50  1.1  riastrad 	    (long double)(x), (long double)(x),				      \
     51  1.1  riastrad 	    (long double)(y), (long double)(y))
     52  1.1  riastrad 
     53  1.1  riastrad ATF_TC(nextafter);
     54  1.1  riastrad ATF_TC_HEAD(nextafter, tc)
     55  1.1  riastrad {
     56  1.1  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafter");
     57  1.1  riastrad }
     58  1.1  riastrad ATF_TC_BODY(nextafter, tc)
     59  1.1  riastrad {
     60  1.1  riastrad 
     61  1.1  riastrad 	CHECK(nextafter(1, 2), 1 + DBL_EPSILON);
     62  1.1  riastrad 	CHECK(nextafter(1 + DBL_EPSILON, 0), 1);
     63  1.1  riastrad 	CHECK(nextafter(1, 0), 1 - DBL_EPSILON/2);
     64  1.1  riastrad 	CHECK(nextafter(1 - DBL_EPSILON/2, 2), 1);
     65  1.1  riastrad 	CHECK(nextafter(-1, -2), -1 - DBL_EPSILON);
     66  1.1  riastrad 	CHECK(nextafter(-1 - DBL_EPSILON, 0), -1);
     67  1.1  riastrad 	CHECK(nextafter(-1, 0), -1 + DBL_EPSILON/2);
     68  1.1  riastrad 	CHECK(nextafter(-1 + DBL_EPSILON/2, -2), -1);
     69  1.1  riastrad }
     70  1.1  riastrad 
     71  1.1  riastrad ATF_TC(nextafterf);
     72  1.1  riastrad ATF_TC_HEAD(nextafterf, tc)
     73  1.1  riastrad {
     74  1.1  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterf");
     75  1.1  riastrad }
     76  1.1  riastrad ATF_TC_BODY(nextafterf, tc)
     77  1.1  riastrad {
     78  1.1  riastrad 
     79  1.1  riastrad 	CHECK(nextafterf(1, 2), 1 + FLT_EPSILON);
     80  1.1  riastrad 	CHECK(nextafterf(1 + FLT_EPSILON, 0), 1);
     81  1.1  riastrad 	CHECK(nextafterf(1, 0), 1 - FLT_EPSILON/2);
     82  1.1  riastrad 	CHECK(nextafterf(1 - FLT_EPSILON/2, 2), 1);
     83  1.1  riastrad 	CHECK(nextafterf(-1, -2), -1 - FLT_EPSILON);
     84  1.1  riastrad 	CHECK(nextafterf(-1 - FLT_EPSILON, 0), -1);
     85  1.1  riastrad 	CHECK(nextafterf(-1, 0), -1 + FLT_EPSILON/2);
     86  1.1  riastrad 	CHECK(nextafterf(-1 + FLT_EPSILON/2, -2), -1);
     87  1.1  riastrad }
     88  1.1  riastrad 
     89  1.1  riastrad ATF_TC(nextafterl);
     90  1.1  riastrad ATF_TC_HEAD(nextafterl, tc)
     91  1.1  riastrad {
     92  1.1  riastrad 	atf_tc_set_md_var(tc, "descr", "nextafterl");
     93  1.1  riastrad }
     94  1.1  riastrad ATF_TC_BODY(nextafterl, tc)
     95  1.1  riastrad {
     96  1.1  riastrad 
     97  1.1  riastrad 	CHECK(nextafterl(1, 2), 1 + LDBL_EPSILON);
     98  1.1  riastrad 	CHECK(nextafterl(1 + LDBL_EPSILON, 0), 1);
     99  1.1  riastrad 	CHECK(nextafterl(1, 0), 1 - LDBL_EPSILON/2);
    100  1.1  riastrad 	CHECK(nextafterl(1 - LDBL_EPSILON/2, 2), 1);
    101  1.1  riastrad 	CHECK(nextafterl(-1, -2), -1 - LDBL_EPSILON);
    102  1.1  riastrad 	CHECK(nextafterl(-1 - LDBL_EPSILON, 0), -1);
    103  1.1  riastrad 	CHECK(nextafterl(-1, 0), -1 + LDBL_EPSILON/2);
    104  1.1  riastrad 	CHECK(nextafterl(-1 + LDBL_EPSILON/2, -2), -1);
    105  1.1  riastrad }
    106  1.1  riastrad 
    107  1.1  riastrad ATF_TC(nexttoward);
    108  1.1  riastrad ATF_TC_HEAD(nexttoward, tc)
    109  1.1  riastrad {
    110  1.1  riastrad 	atf_tc_set_md_var(tc, "descr", "nexttoward");
    111  1.1  riastrad }
    112  1.1  riastrad ATF_TC_BODY(nexttoward, tc)
    113  1.1  riastrad {
    114  1.1  riastrad 
    115  1.1  riastrad 	CHECK(nexttoward(1, 2), 1 + DBL_EPSILON);
    116  1.1  riastrad 	CHECK(nexttoward(1 + DBL_EPSILON, 0), 1);
    117  1.1  riastrad 	CHECK(nexttoward(1, 0), 1 - DBL_EPSILON/2);
    118  1.1  riastrad 	CHECK(nexttoward(1 - DBL_EPSILON/2, 2), 1);
    119  1.1  riastrad 	CHECK(nexttoward(-1, -2), -1 - DBL_EPSILON);
    120  1.1  riastrad 	CHECK(nexttoward(-1 - DBL_EPSILON, 0), -1);
    121  1.1  riastrad 	CHECK(nexttoward(-1, 0), -1 + DBL_EPSILON/2);
    122  1.1  riastrad 	CHECK(nexttoward(-1 + DBL_EPSILON/2, -2), -1);
    123  1.1  riastrad }
    124  1.1  riastrad 
    125  1.1  riastrad ATF_TC(nexttowardf);
    126  1.1  riastrad ATF_TC_HEAD(nexttowardf, tc)
    127  1.1  riastrad {
    128  1.1  riastrad 	atf_tc_set_md_var(tc, "descr", "nexttowardf");
    129  1.1  riastrad }
    130  1.1  riastrad ATF_TC_BODY(nexttowardf, tc)
    131  1.1  riastrad {
    132  1.1  riastrad 
    133  1.1  riastrad 	CHECK(nexttowardf(1, 2), 1 + FLT_EPSILON);
    134  1.1  riastrad 	CHECK(nexttowardf(1 + FLT_EPSILON, 0), 1);
    135  1.1  riastrad 	CHECK(nexttowardf(1, 0), 1 - FLT_EPSILON/2);
    136  1.1  riastrad 	CHECK(nexttowardf(1 - FLT_EPSILON/2, 2), 1);
    137  1.1  riastrad 	CHECK(nexttowardf(-1, -2), -1 - FLT_EPSILON);
    138  1.1  riastrad 	CHECK(nexttowardf(-1 - FLT_EPSILON, 0), -1);
    139  1.1  riastrad 	CHECK(nexttowardf(-1, 0), -1 + FLT_EPSILON/2);
    140  1.1  riastrad 	CHECK(nexttowardf(-1 + FLT_EPSILON/2, -2), -1);
    141  1.1  riastrad }
    142  1.1  riastrad 
    143  1.1  riastrad ATF_TC(nexttowardl);
    144  1.1  riastrad ATF_TC_HEAD(nexttowardl, tc)
    145  1.1  riastrad {
    146  1.1  riastrad 	atf_tc_set_md_var(tc, "descr", "nexttowardl");
    147  1.1  riastrad }
    148  1.1  riastrad ATF_TC_BODY(nexttowardl, tc)
    149  1.1  riastrad {
    150  1.1  riastrad 
    151  1.1  riastrad 	CHECK(nexttowardl(1, 2), 1 + LDBL_EPSILON);
    152  1.1  riastrad 	CHECK(nexttowardl(1 + LDBL_EPSILON, 0), 1);
    153  1.1  riastrad 	CHECK(nexttowardl(1, 0), 1 - LDBL_EPSILON/2);
    154  1.1  riastrad 	CHECK(nexttowardl(1 - LDBL_EPSILON/2, 2), 1);
    155  1.1  riastrad 	CHECK(nexttowardl(-1, -2), -1 - LDBL_EPSILON);
    156  1.1  riastrad 	CHECK(nexttowardl(-1 - LDBL_EPSILON, 0), -1);
    157  1.1  riastrad 	CHECK(nexttowardl(-1, 0), -1 + LDBL_EPSILON/2);
    158  1.1  riastrad 	CHECK(nexttowardl(-1 + LDBL_EPSILON/2, -2), -1);
    159  1.1  riastrad }
    160  1.1  riastrad 
    161  1.2  riastrad #endif	/* __vax__ */
    162  1.2  riastrad 
    163  1.1  riastrad ATF_TP_ADD_TCS(tp)
    164  1.1  riastrad {
    165  1.1  riastrad 
    166  1.2  riastrad #ifdef __vax__
    167  1.2  riastrad 	ATF_TP_ADD_TC(tp, vaxafter);
    168  1.2  riastrad #else
    169  1.1  riastrad 	ATF_TP_ADD_TC(tp, nextafter);
    170  1.1  riastrad 	ATF_TP_ADD_TC(tp, nextafterf);
    171  1.1  riastrad 	ATF_TP_ADD_TC(tp, nextafterl);
    172  1.1  riastrad 	ATF_TP_ADD_TC(tp, nexttoward);
    173  1.1  riastrad 	ATF_TP_ADD_TC(tp, nexttowardf);
    174  1.1  riastrad 	ATF_TP_ADD_TC(tp, nexttowardl);
    175  1.2  riastrad #endif
    176  1.1  riastrad 	return atf_no_error();
    177  1.1  riastrad }
    178