Module Name: src Committed By: riastradh Date: Sun May 5 02:53:02 UTC 2024
Modified Files: src/distrib/sets/lists/debug: mi src/distrib/sets/lists/tests: mi src/tests/lib/libm: Makefile Added Files: src/tests/lib/libm: t_next.c Log Message: tests/lib/libm: Test nextafter/nexttoward and variants. The tests are fairly trivial but should work without any conditionals about floating-point formats. To generate a diff of this commit: cvs rdiff -u -r1.434 -r1.435 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.1314 -r1.1315 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.48 -r1.49 src/tests/lib/libm/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libm/t_next.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/debug/mi diff -u src/distrib/sets/lists/debug/mi:1.434 src/distrib/sets/lists/debug/mi:1.435 --- src/distrib/sets/lists/debug/mi:1.434 Sun Apr 28 18:55:04 2024 +++ src/distrib/sets/lists/debug/mi Sun May 5 02:53:01 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.434 2024/04/28 18:55:04 rillig Exp $ +# $NetBSD: mi,v 1.435 2024/05/05 02:53:01 riastradh Exp $ ./etc/mtree/set.debug comp-sys-root ./usr/lib comp-sys-usr compatdir ./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib @@ -2320,6 +2320,7 @@ ./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-obsolete obsolete,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_log.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_modf.debug tests-lib-debug debug,atf,compattestfile +./usr/libdata/debug/usr/tests/lib/libm/t_next.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_pow.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_precision.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_round.debug tests-lib-debug debug,atf,compattestfile Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1314 src/distrib/sets/lists/tests/mi:1.1315 --- src/distrib/sets/lists/tests/mi:1.1314 Sun Apr 28 14:39:22 2024 +++ src/distrib/sets/lists/tests/mi Sun May 5 02:53:01 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1314 2024/04/28 14:39:22 rillig Exp $ +# $NetBSD: mi,v 1.1315 2024/05/05 02:53:01 riastradh Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -3946,6 +3946,7 @@ ./usr/tests/lib/libm/t_libm tests-obsolete obsolete ./usr/tests/lib/libm/t_log tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_modf tests-lib-tests compattestfile,atf +./usr/tests/lib/libm/t_next tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_pow tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_precision tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_round tests-lib-tests compattestfile,atf Index: src/tests/lib/libm/Makefile diff -u src/tests/lib/libm/Makefile:1.48 src/tests/lib/libm/Makefile:1.49 --- src/tests/lib/libm/Makefile:1.48 Sat Aug 27 08:31:58 2022 +++ src/tests/lib/libm/Makefile Sun May 5 02:53:02 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.48 2022/08/27 08:31:58 christos Exp $ +# $NetBSD: Makefile,v 1.49 2024/05/05 02:53:02 riastradh Exp $ .include <bsd.own.mk> @@ -35,6 +35,7 @@ TESTS_C+= t_infinity TESTS_C+= t_ldexp TESTS_C+= t_log TESTS_C+= t_modf +TESTS_C+= t_next TESTS_C+= t_pow TESTS_C+= t_precision TESTS_C+= t_round Added files: Index: src/tests/lib/libm/t_next.c diff -u /dev/null src/tests/lib/libm/t_next.c:1.1 --- /dev/null Sun May 5 02:53:02 2024 +++ src/tests/lib/libm/t_next.c Sun May 5 02:53:02 2024 @@ -0,0 +1,159 @@ +/* $NetBSD: t_next.c,v 1.1 2024/05/05 02:53:02 riastradh Exp $ */ + +/*- + * Copyright (c) 2024 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_next.c,v 1.1 2024/05/05 02:53:02 riastradh Exp $"); + +#include <atf-c.h> +#include <float.h> +#include <math.h> + +#define CHECK(x, y) \ + ATF_CHECK_EQ_MSG((x), (y), #x"=%La=%Lg, "#y"=%La=%Lg", \ + (long double)(x), (long double)(x), \ + (long double)(y), (long double)(y)) + +ATF_TC(nextafter); +ATF_TC_HEAD(nextafter, tc) +{ + atf_tc_set_md_var(tc, "descr", "nextafter"); +} +ATF_TC_BODY(nextafter, tc) +{ + + CHECK(nextafter(1, 2), 1 + DBL_EPSILON); + CHECK(nextafter(1 + DBL_EPSILON, 0), 1); + CHECK(nextafter(1, 0), 1 - DBL_EPSILON/2); + CHECK(nextafter(1 - DBL_EPSILON/2, 2), 1); + CHECK(nextafter(-1, -2), -1 - DBL_EPSILON); + CHECK(nextafter(-1 - DBL_EPSILON, 0), -1); + CHECK(nextafter(-1, 0), -1 + DBL_EPSILON/2); + CHECK(nextafter(-1 + DBL_EPSILON/2, -2), -1); +} + +ATF_TC(nextafterf); +ATF_TC_HEAD(nextafterf, tc) +{ + atf_tc_set_md_var(tc, "descr", "nextafterf"); +} +ATF_TC_BODY(nextafterf, tc) +{ + + CHECK(nextafterf(1, 2), 1 + FLT_EPSILON); + CHECK(nextafterf(1 + FLT_EPSILON, 0), 1); + CHECK(nextafterf(1, 0), 1 - FLT_EPSILON/2); + CHECK(nextafterf(1 - FLT_EPSILON/2, 2), 1); + CHECK(nextafterf(-1, -2), -1 - FLT_EPSILON); + CHECK(nextafterf(-1 - FLT_EPSILON, 0), -1); + CHECK(nextafterf(-1, 0), -1 + FLT_EPSILON/2); + CHECK(nextafterf(-1 + FLT_EPSILON/2, -2), -1); +} + +ATF_TC(nextafterl); +ATF_TC_HEAD(nextafterl, tc) +{ + atf_tc_set_md_var(tc, "descr", "nextafterl"); +} +ATF_TC_BODY(nextafterl, tc) +{ + + CHECK(nextafterl(1, 2), 1 + LDBL_EPSILON); + CHECK(nextafterl(1 + LDBL_EPSILON, 0), 1); + CHECK(nextafterl(1, 0), 1 - LDBL_EPSILON/2); + CHECK(nextafterl(1 - LDBL_EPSILON/2, 2), 1); + CHECK(nextafterl(-1, -2), -1 - LDBL_EPSILON); + CHECK(nextafterl(-1 - LDBL_EPSILON, 0), -1); + CHECK(nextafterl(-1, 0), -1 + LDBL_EPSILON/2); + CHECK(nextafterl(-1 + LDBL_EPSILON/2, -2), -1); +} + +ATF_TC(nexttoward); +ATF_TC_HEAD(nexttoward, tc) +{ + atf_tc_set_md_var(tc, "descr", "nexttoward"); +} +ATF_TC_BODY(nexttoward, tc) +{ + + CHECK(nexttoward(1, 2), 1 + DBL_EPSILON); + CHECK(nexttoward(1 + DBL_EPSILON, 0), 1); + CHECK(nexttoward(1, 0), 1 - DBL_EPSILON/2); + CHECK(nexttoward(1 - DBL_EPSILON/2, 2), 1); + CHECK(nexttoward(-1, -2), -1 - DBL_EPSILON); + CHECK(nexttoward(-1 - DBL_EPSILON, 0), -1); + CHECK(nexttoward(-1, 0), -1 + DBL_EPSILON/2); + CHECK(nexttoward(-1 + DBL_EPSILON/2, -2), -1); +} + +ATF_TC(nexttowardf); +ATF_TC_HEAD(nexttowardf, tc) +{ + atf_tc_set_md_var(tc, "descr", "nexttowardf"); +} +ATF_TC_BODY(nexttowardf, tc) +{ + + CHECK(nexttowardf(1, 2), 1 + FLT_EPSILON); + CHECK(nexttowardf(1 + FLT_EPSILON, 0), 1); + CHECK(nexttowardf(1, 0), 1 - FLT_EPSILON/2); + CHECK(nexttowardf(1 - FLT_EPSILON/2, 2), 1); + CHECK(nexttowardf(-1, -2), -1 - FLT_EPSILON); + CHECK(nexttowardf(-1 - FLT_EPSILON, 0), -1); + CHECK(nexttowardf(-1, 0), -1 + FLT_EPSILON/2); + CHECK(nexttowardf(-1 + FLT_EPSILON/2, -2), -1); +} + +ATF_TC(nexttowardl); +ATF_TC_HEAD(nexttowardl, tc) +{ + atf_tc_set_md_var(tc, "descr", "nexttowardl"); +} +ATF_TC_BODY(nexttowardl, tc) +{ + + CHECK(nexttowardl(1, 2), 1 + LDBL_EPSILON); + CHECK(nexttowardl(1 + LDBL_EPSILON, 0), 1); + CHECK(nexttowardl(1, 0), 1 - LDBL_EPSILON/2); + CHECK(nexttowardl(1 - LDBL_EPSILON/2, 2), 1); + CHECK(nexttowardl(-1, -2), -1 - LDBL_EPSILON); + CHECK(nexttowardl(-1 - LDBL_EPSILON, 0), -1); + CHECK(nexttowardl(-1, 0), -1 + LDBL_EPSILON/2); + CHECK(nexttowardl(-1 + LDBL_EPSILON/2, -2), -1); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, nextafter); + ATF_TP_ADD_TC(tp, nextafterf); + ATF_TP_ADD_TC(tp, nextafterl); + ATF_TP_ADD_TC(tp, nexttoward); + ATF_TP_ADD_TC(tp, nexttowardf); + ATF_TP_ADD_TC(tp, nexttowardl); + return atf_no_error(); +}