xref: /minix3/tests/lib/libm/t_sinh.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_sinh.c,v 1.6 2014/03/03 10:39:08 martin Exp $ */
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc  * Copyright (c) 2011 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc  * by Jukka Ruohonen.
911be35a1SLionel Sambuc  *
1011be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc  * are met:
1311be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc  *
1911be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc  */
3111be35a1SLionel Sambuc #include <sys/cdefs.h>
32*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_sinh.c,v 1.6 2014/03/03 10:39:08 martin Exp $");
3311be35a1SLionel Sambuc 
3411be35a1SLionel Sambuc #include <atf-c.h>
3511be35a1SLionel Sambuc #include <math.h>
3611be35a1SLionel Sambuc #include <stdio.h>
3711be35a1SLionel Sambuc 
3811be35a1SLionel Sambuc static const struct {
3911be35a1SLionel Sambuc 	double x;
4011be35a1SLionel Sambuc 	double y;
4111be35a1SLionel Sambuc 	double e;
4211be35a1SLionel Sambuc } values[] = {
4311be35a1SLionel Sambuc 	{ -10,   -11013.23287470339, 1e4, },
4411be35a1SLionel Sambuc 	{ -2,    -3.626860407847019, 1,   },
4511be35a1SLionel Sambuc 	{ -1,    -1.175201193643801, 1,   },
4611be35a1SLionel Sambuc 	{ -0.05, -0.050020835937655, 1,   },
4711be35a1SLionel Sambuc 	{ -0.001,-0.001000000166667, 1,   },
4811be35a1SLionel Sambuc 	{  0.001, 0.001000000166667, 1,   },
4911be35a1SLionel Sambuc 	{  0.05,  0.050020835937655, 1,   },
5011be35a1SLionel Sambuc 	{  1,     1.175201193643801, 1,   },
5111be35a1SLionel Sambuc 	{  2,     3.626860407847019, 1,   },
5211be35a1SLionel Sambuc 	{  10,    11013.23287470339, 1e4, },
5311be35a1SLionel Sambuc };
5411be35a1SLionel Sambuc 
5511be35a1SLionel Sambuc /*
5611be35a1SLionel Sambuc  * sinh(3)
5711be35a1SLionel Sambuc  */
5811be35a1SLionel Sambuc ATF_TC(sinh_inrange);
ATF_TC_HEAD(sinh_inrange,tc)5911be35a1SLionel Sambuc ATF_TC_HEAD(sinh_inrange, tc)
6011be35a1SLionel Sambuc {
6111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "sinh(x) for some values");
6211be35a1SLionel Sambuc }
6311be35a1SLionel Sambuc 
ATF_TC_BODY(sinh_inrange,tc)6411be35a1SLionel Sambuc ATF_TC_BODY(sinh_inrange, tc)
6511be35a1SLionel Sambuc {
6611be35a1SLionel Sambuc 	double eps;
6711be35a1SLionel Sambuc 	double x;
6811be35a1SLionel Sambuc 	double y;
6911be35a1SLionel Sambuc 	size_t i;
7011be35a1SLionel Sambuc 
7111be35a1SLionel Sambuc 	for (i = 0; i < __arraycount(values); i++) {
7211be35a1SLionel Sambuc 		x = values[i].x;
7311be35a1SLionel Sambuc 		y = values[i].y;
7411be35a1SLionel Sambuc 		eps = 1e-15 * values[i].e;
7511be35a1SLionel Sambuc 
7611be35a1SLionel Sambuc 		if (fabs(sinh(x) - y) > eps)
7711be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("sinh(%g) != %g\n", x, y);
7811be35a1SLionel Sambuc 	}
7911be35a1SLionel Sambuc }
8011be35a1SLionel Sambuc 
8111be35a1SLionel Sambuc ATF_TC(sinh_nan);
ATF_TC_HEAD(sinh_nan,tc)8211be35a1SLionel Sambuc ATF_TC_HEAD(sinh_nan, tc)
8311be35a1SLionel Sambuc {
8411be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinh(NaN) == NaN");
8511be35a1SLionel Sambuc }
8611be35a1SLionel Sambuc 
ATF_TC_BODY(sinh_nan,tc)8711be35a1SLionel Sambuc ATF_TC_BODY(sinh_nan, tc)
8811be35a1SLionel Sambuc {
8911be35a1SLionel Sambuc 	const double x = 0.0L / 0.0L;
9011be35a1SLionel Sambuc 
9111be35a1SLionel Sambuc 	ATF_CHECK(isnan(x) != 0);
9211be35a1SLionel Sambuc 	ATF_CHECK(isnan(sinh(x)) != 0);
9311be35a1SLionel Sambuc }
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc ATF_TC(sinh_inf_neg);
ATF_TC_HEAD(sinh_inf_neg,tc)9611be35a1SLionel Sambuc ATF_TC_HEAD(sinh_inf_neg, tc)
9711be35a1SLionel Sambuc {
9811be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinh(-Inf) == -Inf");
9911be35a1SLionel Sambuc }
10011be35a1SLionel Sambuc 
ATF_TC_BODY(sinh_inf_neg,tc)10111be35a1SLionel Sambuc ATF_TC_BODY(sinh_inf_neg, tc)
10211be35a1SLionel Sambuc {
10311be35a1SLionel Sambuc 	const double x = -1.0L / 0.0L;
10411be35a1SLionel Sambuc 	double y = sinh(x);
10511be35a1SLionel Sambuc 
10611be35a1SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
10711be35a1SLionel Sambuc 	ATF_CHECK(signbit(y) != 0);
10811be35a1SLionel Sambuc }
10911be35a1SLionel Sambuc 
11011be35a1SLionel Sambuc ATF_TC(sinh_inf_pos);
ATF_TC_HEAD(sinh_inf_pos,tc)11111be35a1SLionel Sambuc ATF_TC_HEAD(sinh_inf_pos, tc)
11211be35a1SLionel Sambuc {
11311be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinh(+Inf) == +Inf");
11411be35a1SLionel Sambuc }
11511be35a1SLionel Sambuc 
ATF_TC_BODY(sinh_inf_pos,tc)11611be35a1SLionel Sambuc ATF_TC_BODY(sinh_inf_pos, tc)
11711be35a1SLionel Sambuc {
11811be35a1SLionel Sambuc 	const double x = 1.0L / 0.0L;
11911be35a1SLionel Sambuc 	double y = sinh(x);
12011be35a1SLionel Sambuc 
12111be35a1SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
12211be35a1SLionel Sambuc 	ATF_CHECK(signbit(y) == 0);
12311be35a1SLionel Sambuc }
12411be35a1SLionel Sambuc 
12511be35a1SLionel Sambuc ATF_TC(sinh_zero_neg);
ATF_TC_HEAD(sinh_zero_neg,tc)12611be35a1SLionel Sambuc ATF_TC_HEAD(sinh_zero_neg, tc)
12711be35a1SLionel Sambuc {
12811be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinh(-0.0) == -0.0");
12911be35a1SLionel Sambuc }
13011be35a1SLionel Sambuc 
ATF_TC_BODY(sinh_zero_neg,tc)13111be35a1SLionel Sambuc ATF_TC_BODY(sinh_zero_neg, tc)
13211be35a1SLionel Sambuc {
13311be35a1SLionel Sambuc 	const double x = -0.0L;
13411be35a1SLionel Sambuc 	double y = sinh(x);
13511be35a1SLionel Sambuc 
13611be35a1SLionel Sambuc 	if (fabs(y) > 0.0 || signbit(y) == 0)
13711be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sinh(-0.0) != -0.0");
13811be35a1SLionel Sambuc }
13911be35a1SLionel Sambuc 
14011be35a1SLionel Sambuc ATF_TC(sinh_zero_pos);
ATF_TC_HEAD(sinh_zero_pos,tc)14111be35a1SLionel Sambuc ATF_TC_HEAD(sinh_zero_pos, tc)
14211be35a1SLionel Sambuc {
14311be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinh(+0.0) == +0.0");
14411be35a1SLionel Sambuc }
14511be35a1SLionel Sambuc 
ATF_TC_BODY(sinh_zero_pos,tc)14611be35a1SLionel Sambuc ATF_TC_BODY(sinh_zero_pos, tc)
14711be35a1SLionel Sambuc {
14811be35a1SLionel Sambuc 	const double x = 0.0L;
14911be35a1SLionel Sambuc 	double y = sinh(x);
15011be35a1SLionel Sambuc 
15111be35a1SLionel Sambuc 	if (fabs(y) > 0.0 || signbit(y) != 0)
15211be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sinh(+0.0) != +0.0");
15311be35a1SLionel Sambuc }
15411be35a1SLionel Sambuc 
15511be35a1SLionel Sambuc /*
15611be35a1SLionel Sambuc  * sinhf(3)
15711be35a1SLionel Sambuc  */
15811be35a1SLionel Sambuc ATF_TC(sinhf_inrange);
ATF_TC_HEAD(sinhf_inrange,tc)15911be35a1SLionel Sambuc ATF_TC_HEAD(sinhf_inrange, tc)
16011be35a1SLionel Sambuc {
16111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "sinhf(x) for some values");
16211be35a1SLionel Sambuc }
16311be35a1SLionel Sambuc 
ATF_TC_BODY(sinhf_inrange,tc)16411be35a1SLionel Sambuc ATF_TC_BODY(sinhf_inrange, tc)
16511be35a1SLionel Sambuc {
16611be35a1SLionel Sambuc 	float eps;
16711be35a1SLionel Sambuc 	float x;
16811be35a1SLionel Sambuc 	float y;
16911be35a1SLionel Sambuc 	size_t i;
17011be35a1SLionel Sambuc 
17111be35a1SLionel Sambuc 	for (i = 0; i < __arraycount(values); i++) {
17211be35a1SLionel Sambuc 		x = values[i].x;
17311be35a1SLionel Sambuc 		y = values[i].y;
17411be35a1SLionel Sambuc 		eps = 1e-6 * values[i].e;
17511be35a1SLionel Sambuc 
17611be35a1SLionel Sambuc 		if (fabsf(sinhf(x) - y) > eps)
17711be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("sinhf(%g) != %g\n", x, y);
17811be35a1SLionel Sambuc 	}
17911be35a1SLionel Sambuc }
18011be35a1SLionel Sambuc 
18111be35a1SLionel Sambuc ATF_TC(sinhf_nan);
ATF_TC_HEAD(sinhf_nan,tc)18211be35a1SLionel Sambuc ATF_TC_HEAD(sinhf_nan, tc)
18311be35a1SLionel Sambuc {
18411be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinhf(NaN) == NaN");
18511be35a1SLionel Sambuc }
18611be35a1SLionel Sambuc 
ATF_TC_BODY(sinhf_nan,tc)18711be35a1SLionel Sambuc ATF_TC_BODY(sinhf_nan, tc)
18811be35a1SLionel Sambuc {
18911be35a1SLionel Sambuc 	const float x = 0.0L / 0.0L;
19011be35a1SLionel Sambuc 
19111be35a1SLionel Sambuc 	ATF_CHECK(isnan(x) != 0);
19211be35a1SLionel Sambuc 	ATF_CHECK(isnan(sinhf(x)) != 0);
19311be35a1SLionel Sambuc }
19411be35a1SLionel Sambuc 
19511be35a1SLionel Sambuc ATF_TC(sinhf_inf_neg);
ATF_TC_HEAD(sinhf_inf_neg,tc)19611be35a1SLionel Sambuc ATF_TC_HEAD(sinhf_inf_neg, tc)
19711be35a1SLionel Sambuc {
19811be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinhf(-Inf) == -Inf");
19911be35a1SLionel Sambuc }
20011be35a1SLionel Sambuc 
ATF_TC_BODY(sinhf_inf_neg,tc)20111be35a1SLionel Sambuc ATF_TC_BODY(sinhf_inf_neg, tc)
20211be35a1SLionel Sambuc {
20311be35a1SLionel Sambuc 	const float x = -1.0L / 0.0L;
20411be35a1SLionel Sambuc 	float y = sinhf(x);
20511be35a1SLionel Sambuc 
20611be35a1SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
20711be35a1SLionel Sambuc 	ATF_CHECK(signbit(y) != 0);
20811be35a1SLionel Sambuc }
20911be35a1SLionel Sambuc 
21011be35a1SLionel Sambuc ATF_TC(sinhf_inf_pos);
ATF_TC_HEAD(sinhf_inf_pos,tc)21111be35a1SLionel Sambuc ATF_TC_HEAD(sinhf_inf_pos, tc)
21211be35a1SLionel Sambuc {
21311be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinhf(+Inf) == +Inf");
21411be35a1SLionel Sambuc }
21511be35a1SLionel Sambuc 
ATF_TC_BODY(sinhf_inf_pos,tc)21611be35a1SLionel Sambuc ATF_TC_BODY(sinhf_inf_pos, tc)
21711be35a1SLionel Sambuc {
21811be35a1SLionel Sambuc 	const float x = 1.0L / 0.0L;
21911be35a1SLionel Sambuc 	float y = sinhf(x);
22011be35a1SLionel Sambuc 
22111be35a1SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
22211be35a1SLionel Sambuc 	ATF_CHECK(signbit(y) == 0);
22311be35a1SLionel Sambuc }
22411be35a1SLionel Sambuc 
22511be35a1SLionel Sambuc ATF_TC(sinhf_zero_neg);
ATF_TC_HEAD(sinhf_zero_neg,tc)22611be35a1SLionel Sambuc ATF_TC_HEAD(sinhf_zero_neg, tc)
22711be35a1SLionel Sambuc {
22811be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinhf(-0.0) == -0.0");
22911be35a1SLionel Sambuc }
23011be35a1SLionel Sambuc 
ATF_TC_BODY(sinhf_zero_neg,tc)23111be35a1SLionel Sambuc ATF_TC_BODY(sinhf_zero_neg, tc)
23211be35a1SLionel Sambuc {
23311be35a1SLionel Sambuc 	const float x = -0.0L;
23411be35a1SLionel Sambuc 	float y = sinhf(x);
23511be35a1SLionel Sambuc 
23611be35a1SLionel Sambuc 	if (fabsf(y) > 0.0 || signbit(y) == 0)
23711be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sinhf(-0.0) != -0.0");
23811be35a1SLionel Sambuc }
23911be35a1SLionel Sambuc 
24011be35a1SLionel Sambuc ATF_TC(sinhf_zero_pos);
ATF_TC_HEAD(sinhf_zero_pos,tc)24111be35a1SLionel Sambuc ATF_TC_HEAD(sinhf_zero_pos, tc)
24211be35a1SLionel Sambuc {
24311be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sinhf(+0.0) == +0.0");
24411be35a1SLionel Sambuc }
24511be35a1SLionel Sambuc 
ATF_TC_BODY(sinhf_zero_pos,tc)24611be35a1SLionel Sambuc ATF_TC_BODY(sinhf_zero_pos, tc)
24711be35a1SLionel Sambuc {
24811be35a1SLionel Sambuc 	const float x = 0.0L;
24911be35a1SLionel Sambuc 	float y = sinhf(x);
25011be35a1SLionel Sambuc 
25111be35a1SLionel Sambuc 	if (fabsf(y) > 0.0 || signbit(y) != 0)
25211be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sinhf(+0.0) != +0.0");
25311be35a1SLionel Sambuc }
25411be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)25511be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
25611be35a1SLionel Sambuc {
25711be35a1SLionel Sambuc 
25811be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinh_inrange);
25911be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinh_nan);
26011be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinh_inf_neg);
26111be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinh_inf_pos);
26211be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinh_zero_neg);
26311be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinh_zero_pos);
26411be35a1SLionel Sambuc 
26511be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinhf_inrange);
26611be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinhf_nan);
26711be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinhf_inf_neg);
26811be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinhf_inf_pos);
26911be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinhf_zero_neg);
27011be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sinhf_zero_pos);
27111be35a1SLionel Sambuc 
27211be35a1SLionel Sambuc 	return atf_no_error();
27311be35a1SLionel Sambuc }
274