1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_asin.c,v 1.3 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
3211be35a1SLionel Sambuc #include <atf-c.h>
3311be35a1SLionel Sambuc #include <math.h>
3411be35a1SLionel Sambuc
3511be35a1SLionel Sambuc static const struct {
3611be35a1SLionel Sambuc double x;
3711be35a1SLionel Sambuc double y;
3811be35a1SLionel Sambuc } values[] = {
3911be35a1SLionel Sambuc { -1.0, -M_PI / 2, },
4011be35a1SLionel Sambuc { -0.9, -1.119769514998634, },
4111be35a1SLionel Sambuc { -0.5, -M_PI / 6, },
4211be35a1SLionel Sambuc { -0.1, -0.1001674211615598, },
4311be35a1SLionel Sambuc { 0.1, 0.1001674211615598, },
4411be35a1SLionel Sambuc { 0.5, M_PI / 6, },
4511be35a1SLionel Sambuc { 0.9, 1.119769514998634, },
4611be35a1SLionel Sambuc { 1.0, M_PI / 2, },
4711be35a1SLionel Sambuc };
4811be35a1SLionel Sambuc
4911be35a1SLionel Sambuc /*
5011be35a1SLionel Sambuc * asin(3)
5111be35a1SLionel Sambuc */
5211be35a1SLionel Sambuc ATF_TC(asin_nan);
ATF_TC_HEAD(asin_nan,tc)5311be35a1SLionel Sambuc ATF_TC_HEAD(asin_nan, tc)
5411be35a1SLionel Sambuc {
5511be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(NaN) == NaN");
5611be35a1SLionel Sambuc }
5711be35a1SLionel Sambuc
ATF_TC_BODY(asin_nan,tc)5811be35a1SLionel Sambuc ATF_TC_BODY(asin_nan, tc)
5911be35a1SLionel Sambuc {
6011be35a1SLionel Sambuc const double x = 0.0L / 0.0L;
6111be35a1SLionel Sambuc
6211be35a1SLionel Sambuc if (isnan(asin(x)) == 0)
6311be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(NaN) != NaN");
6411be35a1SLionel Sambuc }
6511be35a1SLionel Sambuc
6611be35a1SLionel Sambuc ATF_TC(asin_inf_neg);
ATF_TC_HEAD(asin_inf_neg,tc)6711be35a1SLionel Sambuc ATF_TC_HEAD(asin_inf_neg, tc)
6811be35a1SLionel Sambuc {
6911be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(-Inf) == NaN");
7011be35a1SLionel Sambuc }
7111be35a1SLionel Sambuc
ATF_TC_BODY(asin_inf_neg,tc)7211be35a1SLionel Sambuc ATF_TC_BODY(asin_inf_neg, tc)
7311be35a1SLionel Sambuc {
7411be35a1SLionel Sambuc const double x = -1.0L / 0.0L;
7511be35a1SLionel Sambuc
7611be35a1SLionel Sambuc if (isnan(asin(x)) == 0)
7711be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(-Inf) != NaN");
7811be35a1SLionel Sambuc }
7911be35a1SLionel Sambuc
8011be35a1SLionel Sambuc ATF_TC(asin_inf_pos);
ATF_TC_HEAD(asin_inf_pos,tc)8111be35a1SLionel Sambuc ATF_TC_HEAD(asin_inf_pos, tc)
8211be35a1SLionel Sambuc {
8311be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(+Inf) == NaN");
8411be35a1SLionel Sambuc }
8511be35a1SLionel Sambuc
ATF_TC_BODY(asin_inf_pos,tc)8611be35a1SLionel Sambuc ATF_TC_BODY(asin_inf_pos, tc)
8711be35a1SLionel Sambuc {
8811be35a1SLionel Sambuc const double x = 1.0L / 0.0L;
8911be35a1SLionel Sambuc
9011be35a1SLionel Sambuc if (isnan(asin(x)) == 0)
9111be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(+Inf) != NaN");
9211be35a1SLionel Sambuc }
9311be35a1SLionel Sambuc
9411be35a1SLionel Sambuc ATF_TC(asin_range);
ATF_TC_HEAD(asin_range,tc)9511be35a1SLionel Sambuc ATF_TC_HEAD(asin_range, tc)
9611be35a1SLionel Sambuc {
9711be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(x) == NaN, x < -1, x > 1");
9811be35a1SLionel Sambuc }
9911be35a1SLionel Sambuc
ATF_TC_BODY(asin_range,tc)10011be35a1SLionel Sambuc ATF_TC_BODY(asin_range, tc)
10111be35a1SLionel Sambuc {
10211be35a1SLionel Sambuc const double x[] = { -1.1, -1.000000001, 1.1, 1.000000001 };
10311be35a1SLionel Sambuc size_t i;
10411be35a1SLionel Sambuc
10511be35a1SLionel Sambuc for (i = 0; i < __arraycount(x); i++) {
10611be35a1SLionel Sambuc
10711be35a1SLionel Sambuc if (isnan(asin(x[i])) == 0)
10811be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(%f) != NaN", x[i]);
10911be35a1SLionel Sambuc }
11011be35a1SLionel Sambuc }
11111be35a1SLionel Sambuc
11211be35a1SLionel Sambuc ATF_TC(asin_inrange);
ATF_TC_HEAD(asin_inrange,tc)11311be35a1SLionel Sambuc ATF_TC_HEAD(asin_inrange, tc)
11411be35a1SLionel Sambuc {
11511be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(x) for some values");
11611be35a1SLionel Sambuc }
11711be35a1SLionel Sambuc
ATF_TC_BODY(asin_inrange,tc)11811be35a1SLionel Sambuc ATF_TC_BODY(asin_inrange, tc)
11911be35a1SLionel Sambuc {
12011be35a1SLionel Sambuc const double eps = 1.0e-15;
12111be35a1SLionel Sambuc double y;
12211be35a1SLionel Sambuc size_t i;
12311be35a1SLionel Sambuc
12411be35a1SLionel Sambuc for (i = 0; i < __arraycount(values); i++) {
12511be35a1SLionel Sambuc y = asin(values[i].x);
12611be35a1SLionel Sambuc if (fabs(y - values[i].y) > eps)
12711be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(%g) != %g",
12811be35a1SLionel Sambuc values[i].x, values[i].y);
12911be35a1SLionel Sambuc }
13011be35a1SLionel Sambuc }
13111be35a1SLionel Sambuc
13211be35a1SLionel Sambuc ATF_TC(asin_zero_neg);
ATF_TC_HEAD(asin_zero_neg,tc)13311be35a1SLionel Sambuc ATF_TC_HEAD(asin_zero_neg, tc)
13411be35a1SLionel Sambuc {
13511be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(-0.0) == -0.0");
13611be35a1SLionel Sambuc }
13711be35a1SLionel Sambuc
ATF_TC_BODY(asin_zero_neg,tc)13811be35a1SLionel Sambuc ATF_TC_BODY(asin_zero_neg, tc)
13911be35a1SLionel Sambuc {
14011be35a1SLionel Sambuc const double x = -0.0L;
14111be35a1SLionel Sambuc double y = asin(x);
14211be35a1SLionel Sambuc
14311be35a1SLionel Sambuc if (fabs(y) > 0.0 || signbit(y) == 0)
14411be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(-0.0) != -0.0");
14511be35a1SLionel Sambuc }
14611be35a1SLionel Sambuc
14711be35a1SLionel Sambuc ATF_TC(asin_zero_pos);
ATF_TC_HEAD(asin_zero_pos,tc)14811be35a1SLionel Sambuc ATF_TC_HEAD(asin_zero_pos, tc)
14911be35a1SLionel Sambuc {
15011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asin(+0.0) == +0.0");
15111be35a1SLionel Sambuc }
15211be35a1SLionel Sambuc
ATF_TC_BODY(asin_zero_pos,tc)15311be35a1SLionel Sambuc ATF_TC_BODY(asin_zero_pos, tc)
15411be35a1SLionel Sambuc {
15511be35a1SLionel Sambuc const double x = 0.0L;
15611be35a1SLionel Sambuc double y = asin(x);
15711be35a1SLionel Sambuc
15811be35a1SLionel Sambuc if (fabs(y) > 0.0 || signbit(y) != 0)
15911be35a1SLionel Sambuc atf_tc_fail_nonfatal("asin(+0.0) != +0.0");
16011be35a1SLionel Sambuc }
16111be35a1SLionel Sambuc
16211be35a1SLionel Sambuc /*
16311be35a1SLionel Sambuc * asinf(3)
16411be35a1SLionel Sambuc */
16511be35a1SLionel Sambuc ATF_TC(asinf_nan);
ATF_TC_HEAD(asinf_nan,tc)16611be35a1SLionel Sambuc ATF_TC_HEAD(asinf_nan, tc)
16711be35a1SLionel Sambuc {
16811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(NaN) == NaN");
16911be35a1SLionel Sambuc }
17011be35a1SLionel Sambuc
ATF_TC_BODY(asinf_nan,tc)17111be35a1SLionel Sambuc ATF_TC_BODY(asinf_nan, tc)
17211be35a1SLionel Sambuc {
17311be35a1SLionel Sambuc const float x = 0.0L / 0.0L;
17411be35a1SLionel Sambuc
17511be35a1SLionel Sambuc if (isnan(asinf(x)) == 0)
17611be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(NaN) != NaN");
17711be35a1SLionel Sambuc }
17811be35a1SLionel Sambuc
17911be35a1SLionel Sambuc ATF_TC(asinf_inf_neg);
ATF_TC_HEAD(asinf_inf_neg,tc)18011be35a1SLionel Sambuc ATF_TC_HEAD(asinf_inf_neg, tc)
18111be35a1SLionel Sambuc {
18211be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(-Inf) == NaN");
18311be35a1SLionel Sambuc }
18411be35a1SLionel Sambuc
ATF_TC_BODY(asinf_inf_neg,tc)18511be35a1SLionel Sambuc ATF_TC_BODY(asinf_inf_neg, tc)
18611be35a1SLionel Sambuc {
18711be35a1SLionel Sambuc const float x = -1.0L / 0.0L;
18811be35a1SLionel Sambuc
18911be35a1SLionel Sambuc if (isnan(asinf(x)) == 0)
19011be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(-Inf) != NaN");
19111be35a1SLionel Sambuc }
19211be35a1SLionel Sambuc
19311be35a1SLionel Sambuc ATF_TC(asinf_inf_pos);
ATF_TC_HEAD(asinf_inf_pos,tc)19411be35a1SLionel Sambuc ATF_TC_HEAD(asinf_inf_pos, tc)
19511be35a1SLionel Sambuc {
19611be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(+Inf) == NaN");
19711be35a1SLionel Sambuc }
19811be35a1SLionel Sambuc
ATF_TC_BODY(asinf_inf_pos,tc)19911be35a1SLionel Sambuc ATF_TC_BODY(asinf_inf_pos, tc)
20011be35a1SLionel Sambuc {
20111be35a1SLionel Sambuc const float x = 1.0L / 0.0L;
20211be35a1SLionel Sambuc
20311be35a1SLionel Sambuc if (isnan(asinf(x)) == 0)
20411be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(+Inf) != NaN");
20511be35a1SLionel Sambuc }
20611be35a1SLionel Sambuc
20711be35a1SLionel Sambuc ATF_TC(asinf_range);
ATF_TC_HEAD(asinf_range,tc)20811be35a1SLionel Sambuc ATF_TC_HEAD(asinf_range, tc)
20911be35a1SLionel Sambuc {
21011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(x) == NaN, x < -1, x > 1");
21111be35a1SLionel Sambuc }
21211be35a1SLionel Sambuc
ATF_TC_BODY(asinf_range,tc)21311be35a1SLionel Sambuc ATF_TC_BODY(asinf_range, tc)
21411be35a1SLionel Sambuc {
21511be35a1SLionel Sambuc const float x[] = { -1.1, -1.0000001, 1.1, 1.0000001 };
21611be35a1SLionel Sambuc size_t i;
21711be35a1SLionel Sambuc
21811be35a1SLionel Sambuc for (i = 0; i < __arraycount(x); i++) {
21911be35a1SLionel Sambuc
22011be35a1SLionel Sambuc if (isnan(asinf(x[i])) == 0)
22111be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(%f) != NaN", x[i]);
22211be35a1SLionel Sambuc }
22311be35a1SLionel Sambuc }
22411be35a1SLionel Sambuc
22511be35a1SLionel Sambuc ATF_TC(asinf_inrange);
ATF_TC_HEAD(asinf_inrange,tc)22611be35a1SLionel Sambuc ATF_TC_HEAD(asinf_inrange, tc)
22711be35a1SLionel Sambuc {
22811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(x) for some values");
22911be35a1SLionel Sambuc }
23011be35a1SLionel Sambuc
ATF_TC_BODY(asinf_inrange,tc)23111be35a1SLionel Sambuc ATF_TC_BODY(asinf_inrange, tc)
23211be35a1SLionel Sambuc {
23311be35a1SLionel Sambuc const float eps = 1.0e-6;
23411be35a1SLionel Sambuc float x;
23511be35a1SLionel Sambuc float y;
23611be35a1SLionel Sambuc size_t i;
23711be35a1SLionel Sambuc
23811be35a1SLionel Sambuc for (i = 0; i < __arraycount(values); i++) {
23911be35a1SLionel Sambuc x = values[i].x;
24011be35a1SLionel Sambuc y = values[i].y;
24111be35a1SLionel Sambuc if (fabs(asinf(x) - y) > eps)
24211be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(%g) != %g", x, y);
24311be35a1SLionel Sambuc }
24411be35a1SLionel Sambuc }
24511be35a1SLionel Sambuc
24611be35a1SLionel Sambuc ATF_TC(asinf_zero_neg);
ATF_TC_HEAD(asinf_zero_neg,tc)24711be35a1SLionel Sambuc ATF_TC_HEAD(asinf_zero_neg, tc)
24811be35a1SLionel Sambuc {
24911be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(-0.0) == -0.0");
25011be35a1SLionel Sambuc }
25111be35a1SLionel Sambuc
ATF_TC_BODY(asinf_zero_neg,tc)25211be35a1SLionel Sambuc ATF_TC_BODY(asinf_zero_neg, tc)
25311be35a1SLionel Sambuc {
25411be35a1SLionel Sambuc const float x = -0.0L;
25511be35a1SLionel Sambuc float y = asinf(x);
25611be35a1SLionel Sambuc
25711be35a1SLionel Sambuc if (fabsf(y) > 0.0 || signbit(y) == 0)
25811be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(-0.0) != -0.0");
25911be35a1SLionel Sambuc }
26011be35a1SLionel Sambuc
26111be35a1SLionel Sambuc ATF_TC(asinf_zero_pos);
ATF_TC_HEAD(asinf_zero_pos,tc)26211be35a1SLionel Sambuc ATF_TC_HEAD(asinf_zero_pos, tc)
26311be35a1SLionel Sambuc {
26411be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test asinf(+0.0) == +0.0");
26511be35a1SLionel Sambuc }
26611be35a1SLionel Sambuc
ATF_TC_BODY(asinf_zero_pos,tc)26711be35a1SLionel Sambuc ATF_TC_BODY(asinf_zero_pos, tc)
26811be35a1SLionel Sambuc {
26911be35a1SLionel Sambuc const float x = 0.0L;
27011be35a1SLionel Sambuc float y = asinf(x);
27111be35a1SLionel Sambuc
27211be35a1SLionel Sambuc if (fabsf(y) > 0.0 || signbit(y) != 0)
27311be35a1SLionel Sambuc atf_tc_fail_nonfatal("asinf(+0.0) != +0.0");
27411be35a1SLionel Sambuc }
27511be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)27611be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
27711be35a1SLionel Sambuc {
27811be35a1SLionel Sambuc
27911be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_nan);
28011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_inf_neg);
28111be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_inf_pos);
28211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_range);
28311be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_inrange);
28411be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_zero_neg);
28511be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asin_zero_pos);
28611be35a1SLionel Sambuc
28711be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_nan);
28811be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_inf_neg);
28911be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_inf_pos);
29011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_range);
29111be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_inrange);
29211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_zero_neg);
29311be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, asinf_zero_pos);
29411be35a1SLionel Sambuc
29511be35a1SLionel Sambuc return atf_no_error();
29611be35a1SLionel Sambuc }
297