Module Name: src Committed By: gdt Date: Thu Sep 19 19:43:13 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_remquo.c Log Message: tests: Add test for remquo This test currently fails, because remquo has bugs. (A bugfix will be committed soon.) Test vectors derived from results from code by Charles Karney in GeodesicLib/proj, and manually inspected. To generate a diff of this commit: cvs rdiff -u -r1.448 -r1.449 src/distrib/sets/lists/debug/mi cvs rdiff -u -r1.1338 -r1.1339 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.50 -r1.51 src/tests/lib/libm/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libm/t_remquo.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.448 src/distrib/sets/lists/debug/mi:1.449 --- src/distrib/sets/lists/debug/mi:1.448 Mon Sep 9 15:06:29 2024 +++ src/distrib/sets/lists/debug/mi Thu Sep 19 19:43:13 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.448 2024/09/09 15:06:29 riastradh Exp $ +# $NetBSD: mi,v 1.449 2024/09/19 19:43:13 gdt Exp $ # ./etc/mtree/set.debug comp-sys-root ./usr/lib comp-sys-usr compatdir @@ -2337,6 +2337,7 @@ ./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_remquo.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_round.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_scalbn.debug tests-lib-debug debug,atf,compattestfile ./usr/libdata/debug/usr/tests/lib/libm/t_sin.debug tests-lib-debug debug,atf,compattestfile Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1338 src/distrib/sets/lists/tests/mi:1.1339 --- src/distrib/sets/lists/tests/mi:1.1338 Sun Sep 15 13:57:21 2024 +++ src/distrib/sets/lists/tests/mi Thu Sep 19 19:43:13 2024 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1338 2024/09/15 13:57:21 martin Exp $ +# $NetBSD: mi,v 1.1339 2024/09/19 19:43:13 gdt Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -3981,6 +3981,7 @@ ./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_remquo tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_round tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_scalbn tests-lib-tests compattestfile,atf ./usr/tests/lib/libm/t_sin tests-lib-tests compattestfile,atf Index: src/tests/lib/libm/Makefile diff -u src/tests/lib/libm/Makefile:1.50 src/tests/lib/libm/Makefile:1.51 --- src/tests/lib/libm/Makefile:1.50 Mon Sep 9 15:06:29 2024 +++ src/tests/lib/libm/Makefile Thu Sep 19 19:43:13 2024 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.50 2024/09/09 15:06:29 riastradh Exp $ +# $NetBSD: Makefile,v 1.51 2024/09/19 19:43:13 gdt Exp $ .include <bsd.own.mk> @@ -39,6 +39,7 @@ TESTS_C+= t_modf TESTS_C+= t_next TESTS_C+= t_pow TESTS_C+= t_precision +TESTS_C+= t_remquo TESTS_C+= t_round TESTS_C+= t_scalbn TESTS_C+= t_sin Added files: Index: src/tests/lib/libm/t_remquo.c diff -u /dev/null src/tests/lib/libm/t_remquo.c:1.1 --- /dev/null Thu Sep 19 19:43:14 2024 +++ src/tests/lib/libm/t_remquo.c Thu Sep 19 19:43:13 2024 @@ -0,0 +1,114 @@ +/* $NetBSD: t_remquo.c,v 1.1 2024/09/19 19:43:13 gdt Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen and Greg Troxel. + * + * 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 <assert.h> +#include <atf-c.h> +#include <float.h> +#include <math.h> + +static const struct { + double x; + double y; + double r; /* expected */ + int quo; /* expected */ +} args[] = { + { -135.0, -90.0, 45.0, 2 }, + { -45.0, -90.0, -45.0, 8 }, + { 45.0, -90.0, 45.0, -8 }, + { 135.0, -90.0, -45.0, -2 }, + { -180.0, 90.0, -0.0, -2 }, + { -135.0, 90.0, 45.0, -2 }, + { -90.0, 90.0, -0.0, -1 }, + { -45.0, 90.0, -45.0, -8 }, + { 0.0, 90.0, 0.0, 0 }, + { 45.0, 90.0, 45.0, 8 }, + { 90.0, 90.0, 0.0, 1 }, + { 135.0, 90.0, -45.0, 2 }, + { 180.0, 90.0, 0.0, 2 }, +}; + +/* + * remquo(3) + */ +ATF_TC(remquo_args); +ATF_TC_HEAD(remquo_args, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected arguments"); +} + +ATF_TC_BODY(remquo_args, tc) +{ + const double eps = DBL_EPSILON; + size_t i; + + for (i = 0; i < __arraycount(args); i++) { + double x = args[i].x; + double y = args[i].y; + double r; + double r_exp = args[i].r; + int quo; + int quo_exp = args[i].quo; + + bool ok = true; + + r = remquo(x, y, &quo); + + ok &= (fabs(r - r_exp) <= eps); + + /* + * For now, consider 0 to have positive sign. + */ + if (quo_exp < 0 && quo >= 0) + ok = false; + if (quo_exp >= 0 && quo < 0) + ok = false; + + /* + * The specification requires that quo be congruent to + * the integer remainder modulo 2^k for some k >=3. + */ + ok &= ((quo & 0x7) == (quo_exp & 0x7)); + + if (!ok) { + atf_tc_fail_nonfatal("remquo(%g, %g) " + "r/quo expected %g/%d != %g/%d", + x, y, r_exp, quo_exp, r, quo); + } + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, remquo_args); + + return atf_no_error(); +}