Module Name: src Committed By: jruoho Date: Wed Sep 14 05:18:19 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/tests/lib/libm: Makefile Added Files: src/tests/lib/libm: t_cos.c t_sin.c t_tan.c Log Message: Some tests for sine, cosine, and tangent. To generate a diff of this commit: cvs rdiff -u -r1.384 -r1.385 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.8 -r1.9 src/tests/lib/libm/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libm/t_cos.c src/tests/lib/libm/t_sin.c \ src/tests/lib/libm/t_tan.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/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.384 src/distrib/sets/lists/tests/mi:1.385 --- src/distrib/sets/lists/tests/mi:1.384 Mon Sep 12 16:48:48 2011 +++ src/distrib/sets/lists/tests/mi Wed Sep 14 05:18:18 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.384 2011/09/12 16:48:48 jruoho Exp $ +# $NetBSD: mi,v 1.385 2011/09/14 05:18:18 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -547,6 +547,7 @@ ./usr/libdata/debug/usr/tests/lib/libevent/h_event.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libm/t_ceil.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libm/t_cos.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm/t_floor.debug tests-obsolete obsolete ./usr/libdata/debug/usr/tests/lib/libm/t_infinity.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug tests-lib-debug debug,atf @@ -554,6 +555,8 @@ ./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug tests-obsolete obsolete ./usr/libdata/debug/usr/tests/lib/libm/t_round.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm/t_scalbn.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libm/t_sin.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libm/t_tan.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libm/t_tanh.debug tests-lib-debug debug,atf ./usr/libdata/debug/usr/tests/lib/libobjc tests-lib-debug ./usr/libdata/debug/usr/tests/lib/libobjc/t_threads.debug tests-lib-debug debug,atf @@ -2253,6 +2256,7 @@ ./usr/tests/lib/libm tests-lib-tests atf ./usr/tests/lib/libm/Atffile tests-lib-tests atf ./usr/tests/lib/libm/t_ceil tests-lib-tests atf +./usr/tests/lib/libm/t_cos tests-lib-tests atf ./usr/tests/lib/libm/t_floor tests-obsolete obsolete ./usr/tests/lib/libm/t_infinity tests-lib-tests atf ./usr/tests/lib/libm/t_ldexp tests-lib-tests atf @@ -2260,6 +2264,8 @@ ./usr/tests/lib/libm/t_libm tests-obsolete obsolete ./usr/tests/lib/libm/t_round tests-lib-tests atf ./usr/tests/lib/libm/t_scalbn tests-lib-tests atf +./usr/tests/lib/libm/t_sin tests-lib-tests atf +./usr/tests/lib/libm/t_tan tests-lib-tests atf ./usr/tests/lib/libm/t_tanh tests-lib-tests atf ./usr/tests/lib/libobjc tests-lib-tests atf ./usr/tests/lib/libobjc/Atffile tests-lib-tests atf Index: src/tests/lib/libm/Makefile diff -u src/tests/lib/libm/Makefile:1.8 src/tests/lib/libm/Makefile:1.9 --- src/tests/lib/libm/Makefile:1.8 Mon Sep 12 16:48:48 2011 +++ src/tests/lib/libm/Makefile Wed Sep 14 05:18:19 2011 @@ -1,15 +1,18 @@ -# $NetBSD: Makefile,v 1.8 2011/09/12 16:48:48 jruoho Exp $ +# $NetBSD: Makefile,v 1.9 2011/09/14 05:18:19 jruoho Exp $ .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/lib/libm TESTS_C+= t_ceil +TESTS_C+= t_cos TESTS_C+= t_infinity TESTS_C+= t_ldexp TESTS_C+= t_log TESTS_C+= t_round TESTS_C+= t_scalbn +TESTS_C+= t_sin +TESTS_C+= t_tan TESTS_C+= t_tanh LDADD+= -lm Added files: Index: src/tests/lib/libm/t_cos.c diff -u /dev/null src/tests/lib/libm/t_cos.c:1.1 --- /dev/null Wed Sep 14 05:18:19 2011 +++ src/tests/lib/libm/t_cos.c Wed Sep 14 05:18:19 2011 @@ -0,0 +1,277 @@ +/* $NetBSD: t_cos.c,v 1.1 2011/09/14 05:18:19 jruoho 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. + * + * 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 <atf-c.h> +#include <math.h> + +static const struct { + int angle; + double x; + double y; +} angles[] = { + { -180, -3.141592653589793, -1.0000000000000000 }, + { -135, -2.356194490192345, -0.7071067811865476 }, + { -90, -1.570796326794897, 0.0000000000000000 }, + { -45, -0.785398163397448, 0.7071067811865476 }, + { 0, 0.000000000000000, 1.0000000000000000 }, + { 30, 0.523598775598299, 0.8660254037844386 }, + { 45, 0.785398163397448, 0.7071067811865476 }, + { 60, 1.047197551196598, 0.5000000000000000 }, + { 90, 1.570796326794897, 0.0000000000000000 }, + { 120, 2.094395102393195, -0.5000000000000000 }, + { 135, 2.356194490192345, -0.7071067811865476 }, + { 150, 2.617993877991494, -0.8660254037844386 }, + { 180, 3.141592653589793, -1.0000000000000000 }, + { 270, 4.712388980384690, 0.0000000000000000 }, + { 360, 6.283185307179586, 1.0000000000000000 } +}; + +/* + * cos(3) + */ +ATF_TC(cos_angles); +ATF_TC_HEAD(cos_angles, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected angles"); +} + +ATF_TC_BODY(cos_angles, tc) +{ + const double eps = 1.0e-15; + size_t i; + + for (i = 0; i < __arraycount(angles); i++) { + + if (fabs(cos(angles[i].x) - angles[i].y) > eps) + atf_tc_fail_nonfatal("cos(%d deg) != %0.01f", + angles[i].angle, angles[i].y); + } +} + +ATF_TC(cos_nan); +ATF_TC_HEAD(cos_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cos(NaN) == NaN"); +} + +ATF_TC_BODY(cos_nan, tc) +{ +#ifndef __vax__ + const double x = 0.0L / 0.0L; + + ATF_CHECK(isnan(x) != 0); + ATF_CHECK(isnan(cos(x)) != 0); +#endif +} + +ATF_TC(cos_inf_neg); +ATF_TC_HEAD(cos_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cos(-Inf) == NaN"); +} + +ATF_TC_BODY(cos_inf_neg, tc) +{ +#ifndef __vax__ + const double x = -1.0L / 0.0L; + + ATF_CHECK(isnan(cos(x)) != 0); +#endif +} + +ATF_TC(cos_inf_pos); +ATF_TC_HEAD(cos_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cos(+Inf) == NaN"); +} + +ATF_TC_BODY(cos_inf_pos, tc) +{ +#ifndef __vax__ + const double x = 1.0L / 0.0L; + + ATF_CHECK(isnan(cos(x)) != 0); +#endif +} + + +ATF_TC(cos_zero_neg); +ATF_TC_HEAD(cos_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cos(-0.0) == 1.0"); +} + +ATF_TC_BODY(cos_zero_neg, tc) +{ +#ifndef __vax__ + const double x = -0.0L; + + ATF_CHECK(cos(x) == 1.0); +#endif +} + +ATF_TC(cos_zero_pos); +ATF_TC_HEAD(cos_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cos(+0.0) == 1.0"); +} + +ATF_TC_BODY(cos_zero_pos, tc) +{ +#ifndef __vax__ + const double x = 0.0L; + + ATF_CHECK(cos(x) == 1.0); +#endif +} + +/* + * cosf(3) + */ +ATF_TC(cosf_angles); +ATF_TC_HEAD(cosf_angles, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected angles"); +} + +ATF_TC_BODY(cosf_angles, tc) +{ + const float eps = 1.0e-7; + float x, y; + size_t i; + + for (i = 0; i < __arraycount(angles); i++) { + + x = angles[i].x; + y = angles[i].y; + + if (fabs(cosf(x) - y) > eps) + atf_tc_fail_nonfatal("cosf(%d deg) != %0.01f", + angles[i].angle, angles[i].y); + } +} + +ATF_TC(cosf_nan); +ATF_TC_HEAD(cosf_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cosf(NaN) == NaN"); +} + +ATF_TC_BODY(cosf_nan, tc) +{ +#ifndef __vax__ + const float x = 0.0L / 0.0L; + + ATF_CHECK(isnan(x) != 0); + ATF_CHECK(isnan(cosf(x)) != 0); +#endif +} + +ATF_TC(cosf_inf_neg); +ATF_TC_HEAD(cosf_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cosf(-Inf) == NaN"); +} + +ATF_TC_BODY(cosf_inf_neg, tc) +{ +#ifndef __vax__ + const float x = -1.0L / 0.0L; + + ATF_CHECK(isnan(cosf(x)) != 0); +#endif +} + +ATF_TC(cosf_inf_pos); +ATF_TC_HEAD(cosf_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cosf(+Inf) == NaN"); +} + +ATF_TC_BODY(cosf_inf_pos, tc) +{ +#ifndef __vax__ + const float x = 1.0L / 0.0L; + + ATF_CHECK(isnan(cosf(x)) != 0); +#endif +} + + +ATF_TC(cosf_zero_neg); +ATF_TC_HEAD(cosf_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cosf(-0.0) == 1.0"); +} + +ATF_TC_BODY(cosf_zero_neg, tc) +{ +#ifndef __vax__ + const float x = -0.0L; + + ATF_CHECK(cosf(x) == 1.0); +#endif +} + +ATF_TC(cosf_zero_pos); +ATF_TC_HEAD(cosf_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test cosf(+0.0) == 1.0"); +} + +ATF_TC_BODY(cosf_zero_pos, tc) +{ +#ifndef __vax__ + const float x = 0.0L; + + ATF_CHECK(cosf(x) == 1.0); +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, cos_angles); + ATF_TP_ADD_TC(tp, cos_nan); + ATF_TP_ADD_TC(tp, cos_inf_neg); + ATF_TP_ADD_TC(tp, cos_inf_pos); + ATF_TP_ADD_TC(tp, cos_zero_neg); + ATF_TP_ADD_TC(tp, cos_zero_pos); + + ATF_TP_ADD_TC(tp, cosf_angles); + ATF_TP_ADD_TC(tp, cosf_nan); + ATF_TP_ADD_TC(tp, cosf_inf_neg); + ATF_TP_ADD_TC(tp, cosf_inf_pos); + ATF_TP_ADD_TC(tp, cosf_zero_neg); + ATF_TP_ADD_TC(tp, cosf_zero_pos); + + return atf_no_error(); +} Index: src/tests/lib/libm/t_sin.c diff -u /dev/null src/tests/lib/libm/t_sin.c:1.1 --- /dev/null Wed Sep 14 05:18:19 2011 +++ src/tests/lib/libm/t_sin.c Wed Sep 14 05:18:19 2011 @@ -0,0 +1,277 @@ +/* $NetBSD: t_sin.c,v 1.1 2011/09/14 05:18:19 jruoho 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. + * + * 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 <atf-c.h> +#include <math.h> + +static const struct { + int angle; + double x; + double y; +} angles[] = { + { -180, -3.141592653589793, 0.0000000000000000 }, + { -135, -2.356194490192345, -0.7071067811865476 }, + { -90, -1.570796326794897, -1.0000000000000000 }, + { -45, -0.785398163397448, -0.7071067811865476 }, + { 0, 0.000000000000000, 0.0000000000000000 }, + { 30, 0.523598775598299, 0.5000000000000000 }, + { 45, 0.785398163397448, 0.7071067811865476 }, + { 60, 1.047197551196598, 0.8660254037844386 }, + { 90, 1.570796326794897, 1.0000000000000000 }, + { 120, 2.094395102393195, 0.8660254037844386 }, + { 135, 2.356194490192345, 0.7071067811865476 }, + { 150, 2.617993877991494, 0.5000000000000000 }, + { 180, 3.141592653589793, 0.0000000000000000 }, + { 270, 4.712388980384690, -1.0000000000000000 }, + { 360, 6.283185307179586, 0.0000000000000000 } +}; + +/* + * sin(3) + */ +ATF_TC(sin_angles); +ATF_TC_HEAD(sin_angles, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected angles"); +} + +ATF_TC_BODY(sin_angles, tc) +{ + const double eps = 1.0e-15; + size_t i; + + for (i = 0; i < __arraycount(angles); i++) { + + if (fabs(sin(angles[i].x) - angles[i].y) > eps) + atf_tc_fail_nonfatal("sin(%d deg) != %0.01f", + angles[i].angle, angles[i].y); + } +} + +ATF_TC(sin_nan); +ATF_TC_HEAD(sin_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sin(NaN) == NaN"); +} + +ATF_TC_BODY(sin_nan, tc) +{ +#ifndef __vax__ + const double x = 0.0L / 0.0L; + + ATF_CHECK(isnan(x) != 0); + ATF_CHECK(isnan(sin(x)) != 0); +#endif +} + +ATF_TC(sin_inf_neg); +ATF_TC_HEAD(sin_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sin(-Inf) == NaN"); +} + +ATF_TC_BODY(sin_inf_neg, tc) +{ +#ifndef __vax__ + const double x = -1.0L / 0.0L; + + ATF_CHECK(isnan(sin(x)) != 0); +#endif +} + +ATF_TC(sin_inf_pos); +ATF_TC_HEAD(sin_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sin(+Inf) == NaN"); +} + +ATF_TC_BODY(sin_inf_pos, tc) +{ +#ifndef __vax__ + const double x = 1.0L / 0.0L; + + ATF_CHECK(isnan(sin(x)) != 0); +#endif +} + + +ATF_TC(sin_zero_neg); +ATF_TC_HEAD(sin_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sin(-0.0) == -0.0"); +} + +ATF_TC_BODY(sin_zero_neg, tc) +{ +#ifndef __vax__ + const double x = -0.0L; + + ATF_CHECK(sin(x) == x); +#endif +} + +ATF_TC(sin_zero_pos); +ATF_TC_HEAD(sin_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sin(+0.0) == +0.0"); +} + +ATF_TC_BODY(sin_zero_pos, tc) +{ +#ifndef __vax__ + const double x = 0.0L; + + ATF_CHECK(sin(x) == x); +#endif +} + +/* + * sinf(3) + */ +ATF_TC(sinf_angles); +ATF_TC_HEAD(sinf_angles, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected angles"); +} + +ATF_TC_BODY(sinf_angles, tc) +{ + const float eps = 1.0e-6; + float x, y; + size_t i; + + for (i = 0; i < __arraycount(angles); i++) { + + x = angles[i].x; + y = angles[i].y; + + if (fabs(sinf(x) - y) > eps) + atf_tc_fail_nonfatal("sinf(%d deg) != %0.01f", + angles[i].angle, angles[i].y); + } +} + +ATF_TC(sinf_nan); +ATF_TC_HEAD(sinf_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sinf(NaN) == NaN"); +} + +ATF_TC_BODY(sinf_nan, tc) +{ +#ifndef __vax__ + const float x = 0.0L / 0.0L; + + ATF_CHECK(isnan(x) != 0); + ATF_CHECK(isnan(sinf(x)) != 0); +#endif +} + +ATF_TC(sinf_inf_neg); +ATF_TC_HEAD(sinf_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sinf(-Inf) == NaN"); +} + +ATF_TC_BODY(sinf_inf_neg, tc) +{ +#ifndef __vax__ + const float x = -1.0L / 0.0L; + + ATF_CHECK(isnan(sinf(x)) != 0); +#endif +} + +ATF_TC(sinf_inf_pos); +ATF_TC_HEAD(sinf_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sinf(+Inf) == NaN"); +} + +ATF_TC_BODY(sinf_inf_pos, tc) +{ +#ifndef __vax__ + const float x = 1.0L / 0.0L; + + ATF_CHECK(isnan(sinf(x)) != 0); +#endif +} + + +ATF_TC(sinf_zero_neg); +ATF_TC_HEAD(sinf_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sinf(-0.0) == -0.0"); +} + +ATF_TC_BODY(sinf_zero_neg, tc) +{ +#ifndef __vax__ + const float x = -0.0L; + + ATF_CHECK(sinf(x) == x); +#endif +} + +ATF_TC(sinf_zero_pos); +ATF_TC_HEAD(sinf_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test sinf(+0.0) == +0.0"); +} + +ATF_TC_BODY(sinf_zero_pos, tc) +{ +#ifndef __vax__ + const float x = 0.0L; + + ATF_CHECK(sinf(x) == x); +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, sin_angles); + ATF_TP_ADD_TC(tp, sin_nan); + ATF_TP_ADD_TC(tp, sin_inf_neg); + ATF_TP_ADD_TC(tp, sin_inf_pos); + ATF_TP_ADD_TC(tp, sin_zero_neg); + ATF_TP_ADD_TC(tp, sin_zero_pos); + + ATF_TP_ADD_TC(tp, sinf_angles); + ATF_TP_ADD_TC(tp, sinf_nan); + ATF_TP_ADD_TC(tp, sinf_inf_neg); + ATF_TP_ADD_TC(tp, sinf_inf_pos); + ATF_TP_ADD_TC(tp, sinf_zero_neg); + ATF_TP_ADD_TC(tp, sinf_zero_pos); + + return atf_no_error(); +} Index: src/tests/lib/libm/t_tan.c diff -u /dev/null src/tests/lib/libm/t_tan.c:1.1 --- /dev/null Wed Sep 14 05:18:19 2011 +++ src/tests/lib/libm/t_tan.c Wed Sep 14 05:18:19 2011 @@ -0,0 +1,274 @@ +/* $NetBSD: t_tan.c,v 1.1 2011/09/14 05:18:19 jruoho 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. + * + * 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 <atf-c.h> +#include <math.h> + +static const struct { + int angle; + double x; + double y; +} angles[] = { + { -180, -3.141592653589793, 0.0000000000000000 }, + { -135, -2.356194490192345, 1.0000000000000000 }, + { -45, -0.785398163397448, -1.0000000000000000 }, + { 0, 0.000000000000000, 0.0000000000000000 }, + { 30, 0.523598775598299, 0.5773502691896258 }, + { 45, 0.785398163397448, 1.0000000000000000 }, + { 60, 1.047197551196598, 1.7320508075688773 }, + { 120, 2.094395102393195, -1.7320508075688773 }, + { 135, 2.356194490192345, -1.0000000000000000 }, + { 150, 2.617993877991494, -0.5773502691896258 }, + { 180, 3.141592653589793, 0.0000000000000000 }, + { 360, 6.283185307179586, 0.0000000000000000 } +}; + +/* + * tan(3) + */ +ATF_TC(tan_angles); +ATF_TC_HEAD(tan_angles, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected angles"); +} + +ATF_TC_BODY(tan_angles, tc) +{ + const double eps = 1.0e-14; + size_t i; + + for (i = 0; i < __arraycount(angles); i++) { + + if (fabs(tan(angles[i].x) - angles[i].y) > eps) + atf_tc_fail_nonfatal("tan(%d deg) != %0.01f", + angles[i].angle, angles[i].y); + } +} + +ATF_TC(tan_nan); +ATF_TC_HEAD(tan_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tan(NaN) == NaN"); +} + +ATF_TC_BODY(tan_nan, tc) +{ +#ifndef __vax__ + const double x = 0.0L / 0.0L; + + ATF_CHECK(isnan(x) != 0); + ATF_CHECK(isnan(tan(x)) != 0); +#endif +} + +ATF_TC(tan_inf_neg); +ATF_TC_HEAD(tan_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tan(-Inf) == NaN"); +} + +ATF_TC_BODY(tan_inf_neg, tc) +{ +#ifndef __vax__ + const double x = -1.0L / 0.0L; + + ATF_CHECK(isnan(tan(x)) != 0); +#endif +} + +ATF_TC(tan_inf_pos); +ATF_TC_HEAD(tan_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tan(+Inf) == NaN"); +} + +ATF_TC_BODY(tan_inf_pos, tc) +{ +#ifndef __vax__ + const double x = 1.0L / 0.0L; + + ATF_CHECK(isnan(tan(x)) != 0); +#endif +} + + +ATF_TC(tan_zero_neg); +ATF_TC_HEAD(tan_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tan(-0.0) == -0.0"); +} + +ATF_TC_BODY(tan_zero_neg, tc) +{ +#ifndef __vax__ + const double x = -0.0L; + + ATF_CHECK(tan(x) == x); +#endif +} + +ATF_TC(tan_zero_pos); +ATF_TC_HEAD(tan_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tan(+0.0) == +0.0"); +} + +ATF_TC_BODY(tan_zero_pos, tc) +{ +#ifndef __vax__ + const double x = 0.0L; + + ATF_CHECK(tan(x) == x); +#endif +} + +/* + * tanf(3) + */ +ATF_TC(tanf_angles); +ATF_TC_HEAD(tanf_angles, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test some selected angles"); +} + +ATF_TC_BODY(tanf_angles, tc) +{ + const float eps = 1.0e-6; + float x, y; + size_t i; + + for (i = 0; i < __arraycount(angles); i++) { + + x = angles[i].x; + y = angles[i].y; + + if (fabs(tanf(x) - y) > eps) + atf_tc_fail_nonfatal("tanf(%d deg) != %0.01f", + angles[i].angle, angles[i].y); + } +} + +ATF_TC(tanf_nan); +ATF_TC_HEAD(tanf_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tanf(NaN) == NaN"); +} + +ATF_TC_BODY(tanf_nan, tc) +{ +#ifndef __vax__ + const float x = 0.0L / 0.0L; + + ATF_CHECK(isnan(x) != 0); + ATF_CHECK(isnan(tanf(x)) != 0); +#endif +} + +ATF_TC(tanf_inf_neg); +ATF_TC_HEAD(tanf_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tanf(-Inf) == NaN"); +} + +ATF_TC_BODY(tanf_inf_neg, tc) +{ +#ifndef __vax__ + const float x = -1.0L / 0.0L; + + ATF_CHECK(isnan(tanf(x)) != 0); +#endif +} + +ATF_TC(tanf_inf_pos); +ATF_TC_HEAD(tanf_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tanf(+Inf) == NaN"); +} + +ATF_TC_BODY(tanf_inf_pos, tc) +{ +#ifndef __vax__ + const float x = 1.0L / 0.0L; + + ATF_CHECK(isnan(tanf(x)) != 0); +#endif +} + + +ATF_TC(tanf_zero_neg); +ATF_TC_HEAD(tanf_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tanf(-0.0) == -0.0"); +} + +ATF_TC_BODY(tanf_zero_neg, tc) +{ +#ifndef __vax__ + const float x = -0.0L; + + ATF_CHECK(tanf(x) == x); +#endif +} + +ATF_TC(tanf_zero_pos); +ATF_TC_HEAD(tanf_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test tanf(+0.0) == +0.0"); +} + +ATF_TC_BODY(tanf_zero_pos, tc) +{ +#ifndef __vax__ + const float x = 0.0L; + + ATF_CHECK(tanf(x) == x); +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, tan_angles); + ATF_TP_ADD_TC(tp, tan_nan); + ATF_TP_ADD_TC(tp, tan_inf_neg); + ATF_TP_ADD_TC(tp, tan_inf_pos); + ATF_TP_ADD_TC(tp, tan_zero_neg); + ATF_TP_ADD_TC(tp, tan_zero_pos); + + ATF_TP_ADD_TC(tp, tanf_angles); + ATF_TP_ADD_TC(tp, tanf_nan); + ATF_TP_ADD_TC(tp, tanf_inf_neg); + ATF_TP_ADD_TC(tp, tanf_inf_pos); + ATF_TP_ADD_TC(tp, tanf_zero_neg); + ATF_TP_ADD_TC(tp, tanf_zero_pos); + + return atf_no_error(); +}