Module Name: src Committed By: jruoho Date: Sat Sep 17 18:08:36 UTC 2011
Modified Files: src/distrib/sets/lists/tests: mi src/tests/lib/libm: Makefile Added Files: src/tests/lib/libm: t_acos.c t_asin.c t_atan.c Log Message: IEEE checks for the arcus functions. To generate a diff of this commit: cvs rdiff -u -r1.387 -r1.388 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.11 -r1.12 src/tests/lib/libm/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/libm/t_acos.c \ src/tests/lib/libm/t_asin.c src/tests/lib/libm/t_atan.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.387 src/distrib/sets/lists/tests/mi:1.388 --- src/distrib/sets/lists/tests/mi:1.387 Sat Sep 17 12:00:50 2011 +++ src/distrib/sets/lists/tests/mi Sat Sep 17 18:08:36 2011 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.387 2011/09/17 12:00:50 jruoho Exp $ +# $NetBSD: mi,v 1.388 2011/09/17 18:08:36 jruoho Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -546,6 +546,9 @@ ./usr/libdata/debug/usr/tests/lib/libevent tests-lib-debug ./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_acos.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libm/t_asin.debug tests-lib-debug debug,atf +./usr/libdata/debug/usr/tests/lib/libm/t_atan.debug tests-lib-debug debug,atf ./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_erf.debug tests-lib-debug debug,atf @@ -2257,6 +2260,9 @@ ./usr/tests/lib/libevent/t_event tests-lib-tests atf ./usr/tests/lib/libm tests-lib-tests atf ./usr/tests/lib/libm/Atffile tests-lib-tests atf +./usr/tests/lib/libm/t_acos tests-lib-tests atf +./usr/tests/lib/libm/t_asin tests-lib-tests atf +./usr/tests/lib/libm/t_atan 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_erf tests-lib-tests atf Index: src/tests/lib/libm/Makefile diff -u src/tests/lib/libm/Makefile:1.11 src/tests/lib/libm/Makefile:1.12 --- src/tests/lib/libm/Makefile:1.11 Sat Sep 17 12:00:50 2011 +++ src/tests/lib/libm/Makefile Sat Sep 17 18:08:35 2011 @@ -1,9 +1,12 @@ -# $NetBSD: Makefile,v 1.11 2011/09/17 12:00:50 jruoho Exp $ +# $NetBSD: Makefile,v 1.12 2011/09/17 18:08:35 jruoho Exp $ .include <bsd.own.mk> TESTSDIR= ${TESTSBASE}/lib/libm +TESTS_C+= t_acos +TESTS_C+= t_asin +TESTS_C+= t_atan TESTS_C+= t_ceil TESTS_C+= t_cos TESTS_C+= t_erf Added files: Index: src/tests/lib/libm/t_acos.c diff -u /dev/null src/tests/lib/libm/t_acos.c:1.1 --- /dev/null Sat Sep 17 18:08:36 2011 +++ src/tests/lib/libm/t_acos.c Sat Sep 17 18:08:35 2011 @@ -0,0 +1,277 @@ +/* $NetBSD: t_acos.c,v 1.1 2011/09/17 18:08:35 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> + +/* + * acos(3) + */ +ATF_TC(acos_nan); +ATF_TC_HEAD(acos_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acos(NaN) == NaN"); +} + +ATF_TC_BODY(acos_nan, tc) +{ +#ifndef __vax__ + const double x = 0.0L / 0.0L; + + if (isnan(acos(x)) == 0) + atf_tc_fail_nonfatal("acos(NaN) != NaN"); +#endif +} + +ATF_TC(acos_inf_neg); +ATF_TC_HEAD(acos_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acos(-Inf) == NaN"); +} + +ATF_TC_BODY(acos_inf_neg, tc) +{ +#ifndef __vax__ + const double x = -1.0L / 0.0L; + + if (isnan(acos(x)) == 0) + atf_tc_fail_nonfatal("acos(-Inf) != NaN"); +#endif +} + +ATF_TC(acos_inf_pos); +ATF_TC_HEAD(acos_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acos(+Inf) == NaN"); +} + +ATF_TC_BODY(acos_inf_pos, tc) +{ +#ifndef __vax__ + const double x = 1.0L / 0.0L; + + if (isnan(acos(x)) == 0) + atf_tc_fail_nonfatal("acos(+Inf) != NaN"); +#endif +} + +ATF_TC(acos_one_pos); +ATF_TC_HEAD(acos_one_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acos(1.0) == +0.0"); +} + +ATF_TC_BODY(acos_one_pos, tc) +{ +#ifndef __vax__ + const double y = acos(1.0); + + if (fabs(y) > 0.0 || signbit(y) != 0) + atf_tc_fail_nonfatal("acos(1.0) != +0.0"); +#endif +} + +ATF_TC(acos_range); +ATF_TC_HEAD(acos_range, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acos(x) == NaN, x < -1, x > 1"); +} + +ATF_TC_BODY(acos_range, tc) +{ +#ifndef __vax__ + const double x[] = { -1.1, -1.000000001, 1.1, 1.000000001 }; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + if (isnan(acos(x[i])) == 0) + atf_tc_fail_nonfatal("acos(%f) != NaN", x[i]); + } +#endif +} + +ATF_TC(acos_cos); +ATF_TC_HEAD(acos_cos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acos(cos(x)) == x"); +} + +ATF_TC_BODY(acos_cos, tc) +{ +#ifndef __vax__ + const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 }; + const double eps = 1.0e-15; + double y; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + y = acos(cos(x[i])); + + if (fabs(y - x[i]) > eps) + atf_tc_fail_nonfatal("acos(cos(%0.03f)) != %0.03f", + x[i], x[i]); + } +#endif +} + +/* + * acosf(3) + */ +ATF_TC(acosf_nan); +ATF_TC_HEAD(acosf_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acosf(NaN) == NaN"); +} + +ATF_TC_BODY(acosf_nan, tc) +{ +#ifndef __vax__ + const float x = 0.0L / 0.0L; + + if (isnan(acosf(x)) == 0) + atf_tc_fail_nonfatal("acosf(NaN) != NaN"); +#endif +} + +ATF_TC(acosf_inf_neg); +ATF_TC_HEAD(acosf_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acosf(-Inf) == NaN"); +} + +ATF_TC_BODY(acosf_inf_neg, tc) +{ +#ifndef __vax__ + const float x = -1.0L / 0.0L; + + if (isnan(acosf(x)) == 0) + atf_tc_fail_nonfatal("acosf(-Inf) != NaN"); +#endif +} + +ATF_TC(acosf_inf_pos); +ATF_TC_HEAD(acosf_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acosf(+Inf) == NaN"); +} + +ATF_TC_BODY(acosf_inf_pos, tc) +{ +#ifndef __vax__ + const float x = 1.0L / 0.0L; + + if (isnan(acosf(x)) == 0) + atf_tc_fail_nonfatal("acosf(+Inf) != NaN"); +#endif +} + +ATF_TC(acosf_one_pos); +ATF_TC_HEAD(acosf_one_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acosf(1.0) == +0.0"); +} + +ATF_TC_BODY(acosf_one_pos, tc) +{ +#ifndef __vax__ + const float y = acosf(1.0); + + if (fabsf(y) > 0.0 || signbit(y) != 0) + atf_tc_fail_nonfatal("acosf(1.0) != +0.0"); +#endif +} + +ATF_TC(acosf_range); +ATF_TC_HEAD(acosf_range, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acosf(x) == NaN, x < -1, x > 1"); +} + +ATF_TC_BODY(acosf_range, tc) +{ +#ifndef __vax__ + const float x[] = { -1.1, -1.0000001, 1.1, 1.0000001 }; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + if (isnan(acosf(x[i])) == 0) + atf_tc_fail_nonfatal("acosf(%f) != NaN", x[i]); + } +#endif +} + +ATF_TC(acosf_cosf); +ATF_TC_HEAD(acosf_cosf, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test acosf(cosf(x)) == x"); +} + +ATF_TC_BODY(acosf_cosf, tc) +{ +#ifndef __vax__ + const float x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 }; + const float eps = 1.0e-15; + float y; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + y = acosf(cosf(x[i])); + + if (fabsf(y - x[i]) > eps) + atf_tc_fail_nonfatal("acosf(cosf(%0.03f)) != %0.03f", + x[i], x[i]); + } +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, acos_nan); + ATF_TP_ADD_TC(tp, acos_inf_neg); + ATF_TP_ADD_TC(tp, acos_inf_pos); + ATF_TP_ADD_TC(tp, acos_one_pos); + ATF_TP_ADD_TC(tp, acos_range); + ATF_TP_ADD_TC(tp, acos_cos); + + ATF_TP_ADD_TC(tp, acosf_nan); + ATF_TP_ADD_TC(tp, acosf_inf_neg); + ATF_TP_ADD_TC(tp, acosf_inf_pos); + ATF_TP_ADD_TC(tp, acosf_one_pos); + ATF_TP_ADD_TC(tp, acosf_range); + ATF_TP_ADD_TC(tp, acosf_cosf); + + return atf_no_error(); +} Index: src/tests/lib/libm/t_asin.c diff -u /dev/null src/tests/lib/libm/t_asin.c:1.1 --- /dev/null Sat Sep 17 18:08:36 2011 +++ src/tests/lib/libm/t_asin.c Sat Sep 17 18:08:35 2011 @@ -0,0 +1,315 @@ +/* $NetBSD: t_asin.c,v 1.1 2011/09/17 18:08:35 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> + +/* + * asin(3) + */ +ATF_TC(asin_nan); +ATF_TC_HEAD(asin_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(NaN) == NaN"); +} + +ATF_TC_BODY(asin_nan, tc) +{ +#ifndef __vax__ + const double x = 0.0L / 0.0L; + + if (isnan(asin(x)) == 0) + atf_tc_fail_nonfatal("asin(NaN) != NaN"); +#endif +} + +ATF_TC(asin_inf_neg); +ATF_TC_HEAD(asin_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(-Inf) == NaN"); +} + +ATF_TC_BODY(asin_inf_neg, tc) +{ +#ifndef __vax__ + const double x = -1.0L / 0.0L; + + if (isnan(asin(x)) == 0) + atf_tc_fail_nonfatal("asin(-Inf) != NaN"); +#endif +} + +ATF_TC(asin_inf_pos); +ATF_TC_HEAD(asin_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(+Inf) == NaN"); +} + +ATF_TC_BODY(asin_inf_pos, tc) +{ +#ifndef __vax__ + const double x = 1.0L / 0.0L; + + if (isnan(asin(x)) == 0) + atf_tc_fail_nonfatal("asin(+Inf) != NaN"); +#endif +} + +ATF_TC(asin_range); +ATF_TC_HEAD(asin_range, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(x) == NaN, x < -1, x > 1"); +} + +ATF_TC_BODY(asin_range, tc) +{ +#ifndef __vax__ + const double x[] = { -1.1, -1.000000001, 1.1, 1.000000001 }; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + if (isnan(asin(x[i])) == 0) + atf_tc_fail_nonfatal("asin(%f) != NaN", x[i]); + } +#endif +} + +ATF_TC(asin_sin); +ATF_TC_HEAD(asin_sin, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(sin(x)) == x"); +} + +ATF_TC_BODY(asin_sin, tc) +{ +#ifndef __vax__ + const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 }; + const double eps = 1.0e-40; + double y; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + y = asin(sin(x[i])); + + if (fabs(y - x[i]) > eps) + atf_tc_fail_nonfatal("asin(sin(%0.03f)) != %0.03f", + x[i], x[i]); + } +#endif +} + +ATF_TC(asin_zero_neg); +ATF_TC_HEAD(asin_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(-0.0) == -0.0"); +} + +ATF_TC_BODY(asin_zero_neg, tc) +{ +#ifndef __vax__ + const double x = -0.0L; + double y = asin(x); + + if (fabs(y) > 0.0 || signbit(y) == 0) + atf_tc_fail_nonfatal("asin(-0.0) != -0.0"); +#endif +} + +ATF_TC(asin_zero_pos); +ATF_TC_HEAD(asin_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asin(+0.0) == +0.0"); +} + +ATF_TC_BODY(asin_zero_pos, tc) +{ +#ifndef __vax__ + const double x = 0.0L; + double y = asin(x); + + if (fabs(y) > 0.0 || signbit(y) != 0) + atf_tc_fail_nonfatal("asin(+0.0) != +0.0"); +#endif +} + +/* + * asinf(3) + */ +ATF_TC(asinf_nan); +ATF_TC_HEAD(asinf_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(NaN) == NaN"); +} + +ATF_TC_BODY(asinf_nan, tc) +{ +#ifndef __vax__ + const float x = 0.0L / 0.0L; + + if (isnan(asinf(x)) == 0) + atf_tc_fail_nonfatal("asinf(NaN) != NaN"); +#endif +} + +ATF_TC(asinf_inf_neg); +ATF_TC_HEAD(asinf_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(-Inf) == NaN"); +} + +ATF_TC_BODY(asinf_inf_neg, tc) +{ +#ifndef __vax__ + const float x = -1.0L / 0.0L; + + if (isnan(asinf(x)) == 0) + atf_tc_fail_nonfatal("asinf(-Inf) != NaN"); +#endif +} + +ATF_TC(asinf_inf_pos); +ATF_TC_HEAD(asinf_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(+Inf) == NaN"); +} + +ATF_TC_BODY(asinf_inf_pos, tc) +{ +#ifndef __vax__ + const float x = 1.0L / 0.0L; + + if (isnan(asinf(x)) == 0) + atf_tc_fail_nonfatal("asinf(+Inf) != NaN"); +#endif +} + +ATF_TC(asinf_range); +ATF_TC_HEAD(asinf_range, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(x) == NaN, x < -1, x > 1"); +} + +ATF_TC_BODY(asinf_range, tc) +{ +#ifndef __vax__ + const float x[] = { -1.1, -1.0000001, 1.1, 1.0000001 }; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + if (isnan(asinf(x[i])) == 0) + atf_tc_fail_nonfatal("asinf(%f) != NaN", x[i]); + } +#endif +} + +ATF_TC(asinf_sinf); +ATF_TC_HEAD(asinf_sinf, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(sinf(x)) == x"); +} + +ATF_TC_BODY(asinf_sinf, tc) +{ +#ifndef __vax__ + const float x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 }; + const float eps = 1.0e-6; + float y; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + y = asinf(sinf(x[i])); + + if (fabsf(y - x[i]) > eps) + atf_tc_fail_nonfatal("asinf(sinf(%0.03f)) != %0.03f", + x[i], x[i]); + } +#endif +} + +ATF_TC(asinf_zero_neg); +ATF_TC_HEAD(asinf_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(-0.0) == -0.0"); +} + +ATF_TC_BODY(asinf_zero_neg, tc) +{ +#ifndef __vax__ + const float x = -0.0L; + float y = asinf(x); + + if (fabsf(y) > 0.0 || signbit(y) == 0) + atf_tc_fail_nonfatal("asinf(-0.0) != -0.0"); +#endif +} + +ATF_TC(asinf_zero_pos); +ATF_TC_HEAD(asinf_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test asinf(+0.0) == +0.0"); +} + +ATF_TC_BODY(asinf_zero_pos, tc) +{ +#ifndef __vax__ + const float x = 0.0L; + float y = asinf(x); + + if (fabsf(y) > 0.0 || signbit(y) != 0) + atf_tc_fail_nonfatal("asinf(+0.0) != +0.0"); +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, asin_nan); + ATF_TP_ADD_TC(tp, asin_inf_neg); + ATF_TP_ADD_TC(tp, asin_inf_pos); + ATF_TP_ADD_TC(tp, asin_range); + ATF_TP_ADD_TC(tp, asin_sin); + ATF_TP_ADD_TC(tp, asin_zero_neg); + ATF_TP_ADD_TC(tp, asin_zero_pos); + + ATF_TP_ADD_TC(tp, asinf_nan); + ATF_TP_ADD_TC(tp, asinf_inf_neg); + ATF_TP_ADD_TC(tp, asinf_inf_pos); + ATF_TP_ADD_TC(tp, asinf_range); + ATF_TP_ADD_TC(tp, asinf_sinf); + ATF_TP_ADD_TC(tp, asinf_zero_neg); + ATF_TP_ADD_TC(tp, asinf_zero_pos); + + return atf_no_error(); +} Index: src/tests/lib/libm/t_atan.c diff -u /dev/null src/tests/lib/libm/t_atan.c:1.1 --- /dev/null Sat Sep 17 18:08:36 2011 +++ src/tests/lib/libm/t_atan.c Sat Sep 17 18:08:35 2011 @@ -0,0 +1,277 @@ +/* $NetBSD: t_atan.c,v 1.1 2011/09/17 18:08:35 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> + +/* + * atan(3) + */ +ATF_TC(atan_nan); +ATF_TC_HEAD(atan_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atan(NaN) == NaN"); +} + +ATF_TC_BODY(atan_nan, tc) +{ +#ifndef __vax__ + const double x = 0.0L / 0.0L; + + if (isnan(atan(x)) == 0) + atf_tc_fail_nonfatal("atan(NaN) != NaN"); +#endif +} + +ATF_TC(atan_inf_neg); +ATF_TC_HEAD(atan_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atan(-Inf) == -pi/2"); +} + +ATF_TC_BODY(atan_inf_neg, tc) +{ +#ifndef __vax__ + const double x = -1.0L / 0.0L; + const float eps = 1.0e-40; + + if (fabs(atan(x) + M_PI_2) > eps) + atf_tc_fail_nonfatal("atan(-Inf) != -pi/2"); +#endif +} + +ATF_TC(atan_inf_pos); +ATF_TC_HEAD(atan_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atan(+Inf) == pi/2"); +} + +ATF_TC_BODY(atan_inf_pos, tc) +{ +#ifndef __vax__ + const double x = +1.0L / 0.0L; + const float eps = 1.0e-40; + + if (fabs(atan(x) - M_PI_2) > eps) + atf_tc_fail_nonfatal("atan(+Inf) != pi/2"); +#endif +} + +ATF_TC(atan_tan); +ATF_TC_HEAD(atan_tan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atan(tan(x)) == x"); +} + +ATF_TC_BODY(atan_tan, tc) +{ +#ifndef __vax__ + const double x[] = { 0.0, 1.0, M_PI / 2, M_PI / 3, M_PI / 6 }; + const double eps = 1.0e-40; + double y; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + y = atan(tan(x[i])); + + if (fabs(y - x[i]) > eps) + atf_tc_fail_nonfatal("atan(tan(%0.03f)) != %0.03f", + x[i], x[i]); + } +#endif +} + +ATF_TC(atan_zero_neg); +ATF_TC_HEAD(atan_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atan(-0.0) == -0.0"); +} + +ATF_TC_BODY(atan_zero_neg, tc) +{ +#ifndef __vax__ + const double x = -0.0L; + double y = atan(x); + + if (fabs(y) > 0.0 || signbit(y) == 0) + atf_tc_fail_nonfatal("atan(-0.0) != -0.0"); +#endif +} + +ATF_TC(atan_zero_pos); +ATF_TC_HEAD(atan_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atan(+0.0) == +0.0"); +} + +ATF_TC_BODY(atan_zero_pos, tc) +{ +#ifndef __vax__ + const double x = 0.0L; + double y = atan(x); + + if (fabs(y) > 0.0 || signbit(y) != 0) + atf_tc_fail_nonfatal("atan(+0.0) != +0.0"); +#endif +} + +/* + * atanf(3) + */ +ATF_TC(atanf_nan); +ATF_TC_HEAD(atanf_nan, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atanf(NaN) == NaN"); +} + +ATF_TC_BODY(atanf_nan, tc) +{ +#ifndef __vax__ + const float x = 0.0L / 0.0L; + + if (isnan(atanf(x)) == 0) + atf_tc_fail_nonfatal("atanf(NaN) != NaN"); +#endif +} + +ATF_TC(atanf_inf_neg); +ATF_TC_HEAD(atanf_inf_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atanf(-Inf) == -pi/2"); +} + +ATF_TC_BODY(atanf_inf_neg, tc) +{ +#ifndef __vax__ + const float x = -1.0L / 0.0L; + const float eps = 1.0e-7; + + if (fabsf(atanf(x) + M_PI_2) > eps) + atf_tc_fail_nonfatal("atanf(-Inf) != -pi/2"); +#endif +} + +ATF_TC(atanf_inf_pos); +ATF_TC_HEAD(atanf_inf_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atanf(+Inf) == pi/2"); +} + +ATF_TC_BODY(atanf_inf_pos, tc) +{ +#ifndef __vax__ + const float x = +1.0L / 0.0L; + const float eps = 1.0e-7; + + if (fabsf(atanf(x) - M_PI_2) > eps) + atf_tc_fail_nonfatal("atanf(+Inf) != pi/2"); +#endif +} + +ATF_TC(atanf_tanf); +ATF_TC_HEAD(atanf_tanf, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atanf(tanf(x)) == x"); +} + +ATF_TC_BODY(atanf_tanf, tc) +{ +#ifndef __vax__ + const float x[] = { 0.0, 1.0, M_PI / 3, M_PI / 6 }; + const float eps = 1.0e-7; + float y; + size_t i; + + for (i = 0; i < __arraycount(x); i++) { + + y = atanf(tanf(x[i])); + + if (fabsf(y - x[i]) > eps) + atf_tc_fail_nonfatal("atanf(tanf(%0.03f)) != %0.03f", + x[i], x[i]); + } +#endif +} + +ATF_TC(atanf_zero_neg); +ATF_TC_HEAD(atanf_zero_neg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atanf(-0.0) == -0.0"); +} + +ATF_TC_BODY(atanf_zero_neg, tc) +{ +#ifndef __vax__ + const float x = -0.0L; + float y = atanf(x); + + if (fabsf(y) > 0.0 || signbit(y) == 0) + atf_tc_fail_nonfatal("atanf(-0.0) != -0.0"); +#endif +} + +ATF_TC(atanf_zero_pos); +ATF_TC_HEAD(atanf_zero_pos, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test atanf(+0.0) == +0.0"); +} + +ATF_TC_BODY(atanf_zero_pos, tc) +{ +#ifndef __vax__ + const float x = 0.0L; + float y = atanf(x); + + if (fabsf(y) > 0.0 || signbit(y) != 0) + atf_tc_fail_nonfatal("atanf(+0.0) != +0.0"); +#endif +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, atan_nan); + ATF_TP_ADD_TC(tp, atan_inf_neg); + ATF_TP_ADD_TC(tp, atan_inf_pos); + ATF_TP_ADD_TC(tp, atan_tan); + ATF_TP_ADD_TC(tp, atan_zero_neg); + ATF_TP_ADD_TC(tp, atan_zero_pos); + + ATF_TP_ADD_TC(tp, atanf_nan); + ATF_TP_ADD_TC(tp, atanf_inf_neg); + ATF_TP_ADD_TC(tp, atanf_inf_pos); + ATF_TP_ADD_TC(tp, atanf_tanf); + ATF_TP_ADD_TC(tp, atanf_zero_neg); + ATF_TP_ADD_TC(tp, atanf_zero_pos); + + return atf_no_error(); +}