1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_erf.c,v 1.2 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_erf.c,v 1.2 2014/03/03 10:39:08 martin Exp $");
3311be35a1SLionel Sambuc
3411be35a1SLionel Sambuc #include <atf-c.h>
3511be35a1SLionel Sambuc #include <math.h>
3611be35a1SLionel Sambuc
3711be35a1SLionel Sambuc /*
3811be35a1SLionel Sambuc * erf(3)
3911be35a1SLionel Sambuc */
4011be35a1SLionel Sambuc ATF_TC(erf_nan);
ATF_TC_HEAD(erf_nan,tc)4111be35a1SLionel Sambuc ATF_TC_HEAD(erf_nan, tc)
4211be35a1SLionel Sambuc {
4311be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erf(NaN) == NaN");
4411be35a1SLionel Sambuc }
4511be35a1SLionel Sambuc
ATF_TC_BODY(erf_nan,tc)4611be35a1SLionel Sambuc ATF_TC_BODY(erf_nan, tc)
4711be35a1SLionel Sambuc {
4811be35a1SLionel Sambuc const double x = 0.0L / 0.0L;
4911be35a1SLionel Sambuc
5011be35a1SLionel Sambuc ATF_CHECK(isnan(erf(x)) != 0);
5111be35a1SLionel Sambuc }
5211be35a1SLionel Sambuc
5311be35a1SLionel Sambuc ATF_TC(erf_inf_neg);
ATF_TC_HEAD(erf_inf_neg,tc)5411be35a1SLionel Sambuc ATF_TC_HEAD(erf_inf_neg, tc)
5511be35a1SLionel Sambuc {
5611be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erf(-Inf) == -1.0");
5711be35a1SLionel Sambuc }
5811be35a1SLionel Sambuc
ATF_TC_BODY(erf_inf_neg,tc)5911be35a1SLionel Sambuc ATF_TC_BODY(erf_inf_neg, tc)
6011be35a1SLionel Sambuc {
6111be35a1SLionel Sambuc const double x = -1.0L / 0.0L;
6211be35a1SLionel Sambuc
6311be35a1SLionel Sambuc if (erf(x) != -1.0)
6411be35a1SLionel Sambuc atf_tc_fail_nonfatal("erf(-Inf) != -1.0");
6511be35a1SLionel Sambuc }
6611be35a1SLionel Sambuc
6711be35a1SLionel Sambuc ATF_TC(erf_inf_pos);
ATF_TC_HEAD(erf_inf_pos,tc)6811be35a1SLionel Sambuc ATF_TC_HEAD(erf_inf_pos, tc)
6911be35a1SLionel Sambuc {
7011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erf(+Inf) == 1.0");
7111be35a1SLionel Sambuc }
7211be35a1SLionel Sambuc
ATF_TC_BODY(erf_inf_pos,tc)7311be35a1SLionel Sambuc ATF_TC_BODY(erf_inf_pos, tc)
7411be35a1SLionel Sambuc {
7511be35a1SLionel Sambuc const double x = 1.0L / 0.0L;
7611be35a1SLionel Sambuc
7711be35a1SLionel Sambuc if (erf(x) != 1.0)
7811be35a1SLionel Sambuc atf_tc_fail_nonfatal("erf(+Inf) != 1.0");
7911be35a1SLionel Sambuc }
8011be35a1SLionel Sambuc
8111be35a1SLionel Sambuc ATF_TC(erf_zero_neg);
ATF_TC_HEAD(erf_zero_neg,tc)8211be35a1SLionel Sambuc ATF_TC_HEAD(erf_zero_neg, tc)
8311be35a1SLionel Sambuc {
8411be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erf(-0.0) == -0.0");
8511be35a1SLionel Sambuc }
8611be35a1SLionel Sambuc
ATF_TC_BODY(erf_zero_neg,tc)8711be35a1SLionel Sambuc ATF_TC_BODY(erf_zero_neg, tc)
8811be35a1SLionel Sambuc {
8911be35a1SLionel Sambuc const double x = -0.0L;
9011be35a1SLionel Sambuc double y = erf(x);
9111be35a1SLionel Sambuc
9211be35a1SLionel Sambuc if (fabs(y) > 0.0 || signbit(y) == 0)
9311be35a1SLionel Sambuc atf_tc_fail_nonfatal("erf(-0.0) != -0.0");
9411be35a1SLionel Sambuc }
9511be35a1SLionel Sambuc
9611be35a1SLionel Sambuc ATF_TC(erf_zero_pos);
ATF_TC_HEAD(erf_zero_pos,tc)9711be35a1SLionel Sambuc ATF_TC_HEAD(erf_zero_pos, tc)
9811be35a1SLionel Sambuc {
9911be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erf(+0.0) == +0.0");
10011be35a1SLionel Sambuc }
10111be35a1SLionel Sambuc
ATF_TC_BODY(erf_zero_pos,tc)10211be35a1SLionel Sambuc ATF_TC_BODY(erf_zero_pos, tc)
10311be35a1SLionel Sambuc {
10411be35a1SLionel Sambuc const double x = 0.0L;
10511be35a1SLionel Sambuc double y = erf(x);
10611be35a1SLionel Sambuc
10711be35a1SLionel Sambuc if (fabs(y) > 0.0 || signbit(y) != 0)
10811be35a1SLionel Sambuc atf_tc_fail_nonfatal("erf(+0.0) != +0.0");
10911be35a1SLionel Sambuc }
11011be35a1SLionel Sambuc
11111be35a1SLionel Sambuc /*
11211be35a1SLionel Sambuc * erff(3)
11311be35a1SLionel Sambuc */
11411be35a1SLionel Sambuc ATF_TC(erff_nan);
ATF_TC_HEAD(erff_nan,tc)11511be35a1SLionel Sambuc ATF_TC_HEAD(erff_nan, tc)
11611be35a1SLionel Sambuc {
11711be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erff(NaN) == NaN");
11811be35a1SLionel Sambuc }
11911be35a1SLionel Sambuc
ATF_TC_BODY(erff_nan,tc)12011be35a1SLionel Sambuc ATF_TC_BODY(erff_nan, tc)
12111be35a1SLionel Sambuc {
12211be35a1SLionel Sambuc const float x = 0.0L / 0.0L;
12311be35a1SLionel Sambuc
12411be35a1SLionel Sambuc ATF_CHECK(isnan(erff(x)) != 0);
12511be35a1SLionel Sambuc }
12611be35a1SLionel Sambuc
12711be35a1SLionel Sambuc ATF_TC(erff_inf_neg);
ATF_TC_HEAD(erff_inf_neg,tc)12811be35a1SLionel Sambuc ATF_TC_HEAD(erff_inf_neg, tc)
12911be35a1SLionel Sambuc {
13011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erff(-Inf) == -1.0");
13111be35a1SLionel Sambuc }
13211be35a1SLionel Sambuc
ATF_TC_BODY(erff_inf_neg,tc)13311be35a1SLionel Sambuc ATF_TC_BODY(erff_inf_neg, tc)
13411be35a1SLionel Sambuc {
13511be35a1SLionel Sambuc const float x = -1.0L / 0.0L;
13611be35a1SLionel Sambuc
13711be35a1SLionel Sambuc if (erff(x) != -1.0)
13811be35a1SLionel Sambuc atf_tc_fail_nonfatal("erff(-Inf) != -1.0");
13911be35a1SLionel Sambuc }
14011be35a1SLionel Sambuc
14111be35a1SLionel Sambuc ATF_TC(erff_inf_pos);
ATF_TC_HEAD(erff_inf_pos,tc)14211be35a1SLionel Sambuc ATF_TC_HEAD(erff_inf_pos, tc)
14311be35a1SLionel Sambuc {
14411be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erff(+Inf) == 1.0");
14511be35a1SLionel Sambuc }
14611be35a1SLionel Sambuc
ATF_TC_BODY(erff_inf_pos,tc)14711be35a1SLionel Sambuc ATF_TC_BODY(erff_inf_pos, tc)
14811be35a1SLionel Sambuc {
14911be35a1SLionel Sambuc const float x = 1.0L / 0.0L;
15011be35a1SLionel Sambuc
15111be35a1SLionel Sambuc if (erff(x) != 1.0)
15211be35a1SLionel Sambuc atf_tc_fail_nonfatal("erff(+Inf) != 1.0");
15311be35a1SLionel Sambuc }
15411be35a1SLionel Sambuc
15511be35a1SLionel Sambuc ATF_TC(erff_zero_neg);
ATF_TC_HEAD(erff_zero_neg,tc)15611be35a1SLionel Sambuc ATF_TC_HEAD(erff_zero_neg, tc)
15711be35a1SLionel Sambuc {
15811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erff(-0.0) == -0.0");
15911be35a1SLionel Sambuc }
16011be35a1SLionel Sambuc
ATF_TC_BODY(erff_zero_neg,tc)16111be35a1SLionel Sambuc ATF_TC_BODY(erff_zero_neg, tc)
16211be35a1SLionel Sambuc {
16311be35a1SLionel Sambuc const float x = -0.0L;
16411be35a1SLionel Sambuc float y = erff(x);
16511be35a1SLionel Sambuc
16611be35a1SLionel Sambuc if (fabsf(y) > 0.0 || signbit(y) == 0)
16711be35a1SLionel Sambuc atf_tc_fail_nonfatal("erff(-0.0) != -0.0");
16811be35a1SLionel Sambuc }
16911be35a1SLionel Sambuc
17011be35a1SLionel Sambuc ATF_TC(erff_zero_pos);
ATF_TC_HEAD(erff_zero_pos,tc)17111be35a1SLionel Sambuc ATF_TC_HEAD(erff_zero_pos, tc)
17211be35a1SLionel Sambuc {
17311be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erff(+0.0) == +0.0");
17411be35a1SLionel Sambuc }
17511be35a1SLionel Sambuc
ATF_TC_BODY(erff_zero_pos,tc)17611be35a1SLionel Sambuc ATF_TC_BODY(erff_zero_pos, tc)
17711be35a1SLionel Sambuc {
17811be35a1SLionel Sambuc const float x = 0.0L;
17911be35a1SLionel Sambuc float y = erff(x);
18011be35a1SLionel Sambuc
18111be35a1SLionel Sambuc if (fabsf(y) > 0.0 || signbit(y) != 0)
18211be35a1SLionel Sambuc atf_tc_fail_nonfatal("erff(+0.0) != +0.0");
18311be35a1SLionel Sambuc }
18411be35a1SLionel Sambuc
18511be35a1SLionel Sambuc /*
18611be35a1SLionel Sambuc * erfc(3)
18711be35a1SLionel Sambuc */
18811be35a1SLionel Sambuc ATF_TC(erfc_nan);
ATF_TC_HEAD(erfc_nan,tc)18911be35a1SLionel Sambuc ATF_TC_HEAD(erfc_nan, tc)
19011be35a1SLionel Sambuc {
19111be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erfc(NaN) == NaN");
19211be35a1SLionel Sambuc }
19311be35a1SLionel Sambuc
ATF_TC_BODY(erfc_nan,tc)19411be35a1SLionel Sambuc ATF_TC_BODY(erfc_nan, tc)
19511be35a1SLionel Sambuc {
19611be35a1SLionel Sambuc const double x = 0.0L / 0.0L;
19711be35a1SLionel Sambuc
19811be35a1SLionel Sambuc ATF_CHECK(isnan(erfc(x)) != 0);
19911be35a1SLionel Sambuc }
20011be35a1SLionel Sambuc
20111be35a1SLionel Sambuc ATF_TC(erfc_inf_neg);
ATF_TC_HEAD(erfc_inf_neg,tc)20211be35a1SLionel Sambuc ATF_TC_HEAD(erfc_inf_neg, tc)
20311be35a1SLionel Sambuc {
20411be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erfc(-Inf) == 2.0");
20511be35a1SLionel Sambuc }
20611be35a1SLionel Sambuc
ATF_TC_BODY(erfc_inf_neg,tc)20711be35a1SLionel Sambuc ATF_TC_BODY(erfc_inf_neg, tc)
20811be35a1SLionel Sambuc {
20911be35a1SLionel Sambuc const double x = -1.0L / 0.0L;
21011be35a1SLionel Sambuc
21111be35a1SLionel Sambuc if (erfc(x) != 2.0)
21211be35a1SLionel Sambuc atf_tc_fail_nonfatal("erfc(-Inf) != 2.0");
21311be35a1SLionel Sambuc }
21411be35a1SLionel Sambuc
21511be35a1SLionel Sambuc ATF_TC(erfc_inf_pos);
ATF_TC_HEAD(erfc_inf_pos,tc)21611be35a1SLionel Sambuc ATF_TC_HEAD(erfc_inf_pos, tc)
21711be35a1SLionel Sambuc {
21811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erfc(+Inf) == +0.0");
21911be35a1SLionel Sambuc }
22011be35a1SLionel Sambuc
ATF_TC_BODY(erfc_inf_pos,tc)22111be35a1SLionel Sambuc ATF_TC_BODY(erfc_inf_pos, tc)
22211be35a1SLionel Sambuc {
22311be35a1SLionel Sambuc const double x = 1.0L / 0.0L;
22411be35a1SLionel Sambuc double y = erfc(x);
22511be35a1SLionel Sambuc
22611be35a1SLionel Sambuc if (fabs(y) > 0.0 || signbit(y) != 0)
22711be35a1SLionel Sambuc atf_tc_fail_nonfatal("erfc(+Inf) != +0.0");
22811be35a1SLionel Sambuc }
22911be35a1SLionel Sambuc
23011be35a1SLionel Sambuc /*
23111be35a1SLionel Sambuc * erfcf(3)
23211be35a1SLionel Sambuc */
23311be35a1SLionel Sambuc ATF_TC(erfcf_nan);
ATF_TC_HEAD(erfcf_nan,tc)23411be35a1SLionel Sambuc ATF_TC_HEAD(erfcf_nan, tc)
23511be35a1SLionel Sambuc {
23611be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erfcf(NaN) == NaN");
23711be35a1SLionel Sambuc }
23811be35a1SLionel Sambuc
ATF_TC_BODY(erfcf_nan,tc)23911be35a1SLionel Sambuc ATF_TC_BODY(erfcf_nan, tc)
24011be35a1SLionel Sambuc {
24111be35a1SLionel Sambuc const float x = 0.0L / 0.0L;
24211be35a1SLionel Sambuc
24311be35a1SLionel Sambuc ATF_CHECK(isnan(erfcf(x)) != 0);
24411be35a1SLionel Sambuc }
24511be35a1SLionel Sambuc
24611be35a1SLionel Sambuc ATF_TC(erfcf_inf_neg);
ATF_TC_HEAD(erfcf_inf_neg,tc)24711be35a1SLionel Sambuc ATF_TC_HEAD(erfcf_inf_neg, tc)
24811be35a1SLionel Sambuc {
24911be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erfcf(-Inf) == 2.0");
25011be35a1SLionel Sambuc }
25111be35a1SLionel Sambuc
ATF_TC_BODY(erfcf_inf_neg,tc)25211be35a1SLionel Sambuc ATF_TC_BODY(erfcf_inf_neg, tc)
25311be35a1SLionel Sambuc {
25411be35a1SLionel Sambuc const float x = -1.0L / 0.0L;
25511be35a1SLionel Sambuc
25611be35a1SLionel Sambuc if (erfcf(x) != 2.0)
25711be35a1SLionel Sambuc atf_tc_fail_nonfatal("erfcf(-Inf) != 2.0");
25811be35a1SLionel Sambuc }
25911be35a1SLionel Sambuc
26011be35a1SLionel Sambuc ATF_TC(erfcf_inf_pos);
ATF_TC_HEAD(erfcf_inf_pos,tc)26111be35a1SLionel Sambuc ATF_TC_HEAD(erfcf_inf_pos, tc)
26211be35a1SLionel Sambuc {
26311be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test erfcf(+Inf) == +0.0");
26411be35a1SLionel Sambuc }
26511be35a1SLionel Sambuc
ATF_TC_BODY(erfcf_inf_pos,tc)26611be35a1SLionel Sambuc ATF_TC_BODY(erfcf_inf_pos, tc)
26711be35a1SLionel Sambuc {
26811be35a1SLionel Sambuc const float x = 1.0L / 0.0L;
26911be35a1SLionel Sambuc float y = erfcf(x);
27011be35a1SLionel Sambuc
27111be35a1SLionel Sambuc if (fabsf(y) > 0.0 || signbit(y) != 0)
27211be35a1SLionel Sambuc atf_tc_fail_nonfatal("erfcf(+Inf) != +0.0");
27311be35a1SLionel Sambuc }
27411be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)27511be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
27611be35a1SLionel Sambuc {
27711be35a1SLionel Sambuc
27811be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erf_nan);
27911be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erf_inf_neg);
28011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erf_inf_pos);
28111be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erf_zero_neg);
28211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erf_zero_pos);
28311be35a1SLionel Sambuc
28411be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erff_nan);
28511be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erff_inf_neg);
28611be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erff_inf_pos);
28711be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erff_zero_neg);
28811be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erff_zero_pos);
28911be35a1SLionel Sambuc
29011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erfc_nan);
29111be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erfc_inf_neg);
29211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erfc_inf_pos);
29311be35a1SLionel Sambuc
29411be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erfcf_nan);
29511be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erfcf_inf_neg);
29611be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, erfcf_inf_pos);
29711be35a1SLionel Sambuc
29811be35a1SLionel Sambuc return atf_no_error();
29911be35a1SLionel Sambuc }
300