1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_tanh.c,v 1.7 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_tanh.c,v 1.7 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 * tanh(3)
3911be35a1SLionel Sambuc */
4011be35a1SLionel Sambuc ATF_TC(tanh_nan);
ATF_TC_HEAD(tanh_nan,tc)4111be35a1SLionel Sambuc ATF_TC_HEAD(tanh_nan, tc)
4211be35a1SLionel Sambuc {
4311be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanh(NaN) == NaN");
4411be35a1SLionel Sambuc }
4511be35a1SLionel Sambuc
ATF_TC_BODY(tanh_nan,tc)4611be35a1SLionel Sambuc ATF_TC_BODY(tanh_nan, tc)
4711be35a1SLionel Sambuc {
4811be35a1SLionel Sambuc const double x = 0.0L / 0.0L;
4911be35a1SLionel Sambuc
5011be35a1SLionel Sambuc ATF_CHECK(isnan(x) != 0);
5111be35a1SLionel Sambuc ATF_CHECK(isnan(tanh(x)) != 0);
5211be35a1SLionel Sambuc }
5311be35a1SLionel Sambuc
5411be35a1SLionel Sambuc ATF_TC(tanh_inf_neg);
ATF_TC_HEAD(tanh_inf_neg,tc)5511be35a1SLionel Sambuc ATF_TC_HEAD(tanh_inf_neg, tc)
5611be35a1SLionel Sambuc {
5711be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanh(-Inf) == -1.0");
5811be35a1SLionel Sambuc }
5911be35a1SLionel Sambuc
ATF_TC_BODY(tanh_inf_neg,tc)6011be35a1SLionel Sambuc ATF_TC_BODY(tanh_inf_neg, tc)
6111be35a1SLionel Sambuc {
6211be35a1SLionel Sambuc const double x = -1.0L / 0.0L;
6311be35a1SLionel Sambuc
6411be35a1SLionel Sambuc ATF_CHECK(tanh(x) == -1.0);
6511be35a1SLionel Sambuc }
6611be35a1SLionel Sambuc
6711be35a1SLionel Sambuc ATF_TC(tanh_inf_pos);
ATF_TC_HEAD(tanh_inf_pos,tc)6811be35a1SLionel Sambuc ATF_TC_HEAD(tanh_inf_pos, tc)
6911be35a1SLionel Sambuc {
7011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanh(+Inf) == +1.0");
7111be35a1SLionel Sambuc }
7211be35a1SLionel Sambuc
ATF_TC_BODY(tanh_inf_pos,tc)7311be35a1SLionel Sambuc ATF_TC_BODY(tanh_inf_pos, tc)
7411be35a1SLionel Sambuc {
7511be35a1SLionel Sambuc const double x = 1.0L / 0.0L;
7611be35a1SLionel Sambuc
7711be35a1SLionel Sambuc ATF_CHECK(tanh(x) == 1.0);
7811be35a1SLionel Sambuc }
7911be35a1SLionel Sambuc
8011be35a1SLionel Sambuc ATF_TC(tanh_zero_neg);
ATF_TC_HEAD(tanh_zero_neg,tc)8111be35a1SLionel Sambuc ATF_TC_HEAD(tanh_zero_neg, tc)
8211be35a1SLionel Sambuc {
8311be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanh(-0.0) == -0.0");
8411be35a1SLionel Sambuc }
8511be35a1SLionel Sambuc
ATF_TC_BODY(tanh_zero_neg,tc)8611be35a1SLionel Sambuc ATF_TC_BODY(tanh_zero_neg, tc)
8711be35a1SLionel Sambuc {
8811be35a1SLionel Sambuc const double x = -0.0L;
8911be35a1SLionel Sambuc double y = tanh(x);
9011be35a1SLionel Sambuc
9111be35a1SLionel Sambuc ATF_CHECK(x == y);
9211be35a1SLionel Sambuc ATF_CHECK(signbit(x) != 0);
9311be35a1SLionel Sambuc
9411be35a1SLionel Sambuc ATF_REQUIRE_MSG(signbit(y) != 0,
9511be35a1SLionel Sambuc "compiler bug, waiting for newer gcc import, see PR lib/44057");
9611be35a1SLionel Sambuc }
9711be35a1SLionel Sambuc
9811be35a1SLionel Sambuc ATF_TC(tanh_zero_pos);
ATF_TC_HEAD(tanh_zero_pos,tc)9911be35a1SLionel Sambuc ATF_TC_HEAD(tanh_zero_pos, tc)
10011be35a1SLionel Sambuc {
10111be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanh(+0.0) == +0.0");
10211be35a1SLionel Sambuc }
10311be35a1SLionel Sambuc
ATF_TC_BODY(tanh_zero_pos,tc)10411be35a1SLionel Sambuc ATF_TC_BODY(tanh_zero_pos, tc)
10511be35a1SLionel Sambuc {
10611be35a1SLionel Sambuc const double x = 0.0L;
10711be35a1SLionel Sambuc double y = tanh(x);
10811be35a1SLionel Sambuc
10911be35a1SLionel Sambuc ATF_CHECK(x == y);
11011be35a1SLionel Sambuc ATF_CHECK(signbit(x) == 0);
11111be35a1SLionel Sambuc ATF_CHECK(signbit(y) == 0);
11211be35a1SLionel Sambuc }
11311be35a1SLionel Sambuc
11411be35a1SLionel Sambuc /*
11511be35a1SLionel Sambuc * tanhf(3)
11611be35a1SLionel Sambuc */
11711be35a1SLionel Sambuc ATF_TC(tanhf_nan);
ATF_TC_HEAD(tanhf_nan,tc)11811be35a1SLionel Sambuc ATF_TC_HEAD(tanhf_nan, tc)
11911be35a1SLionel Sambuc {
12011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanhf(NaN) == NaN");
12111be35a1SLionel Sambuc }
12211be35a1SLionel Sambuc
ATF_TC_BODY(tanhf_nan,tc)12311be35a1SLionel Sambuc ATF_TC_BODY(tanhf_nan, tc)
12411be35a1SLionel Sambuc {
12511be35a1SLionel Sambuc const float x = 0.0L / 0.0L;
12611be35a1SLionel Sambuc
12711be35a1SLionel Sambuc ATF_CHECK(isnan(x) != 0);
12811be35a1SLionel Sambuc ATF_CHECK(isnan(tanhf(x)) != 0);
12911be35a1SLionel Sambuc }
13011be35a1SLionel Sambuc
13111be35a1SLionel Sambuc ATF_TC(tanhf_inf_neg);
ATF_TC_HEAD(tanhf_inf_neg,tc)13211be35a1SLionel Sambuc ATF_TC_HEAD(tanhf_inf_neg, tc)
13311be35a1SLionel Sambuc {
13411be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanhf(-Inf) == -1.0");
13511be35a1SLionel Sambuc }
13611be35a1SLionel Sambuc
ATF_TC_BODY(tanhf_inf_neg,tc)13711be35a1SLionel Sambuc ATF_TC_BODY(tanhf_inf_neg, tc)
13811be35a1SLionel Sambuc {
13911be35a1SLionel Sambuc const float x = -1.0L / 0.0L;
14011be35a1SLionel Sambuc
14111be35a1SLionel Sambuc ATF_CHECK(tanhf(x) == -1.0);
14211be35a1SLionel Sambuc }
14311be35a1SLionel Sambuc
14411be35a1SLionel Sambuc ATF_TC(tanhf_inf_pos);
ATF_TC_HEAD(tanhf_inf_pos,tc)14511be35a1SLionel Sambuc ATF_TC_HEAD(tanhf_inf_pos, tc)
14611be35a1SLionel Sambuc {
14711be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanhf(+Inf) == +1.0");
14811be35a1SLionel Sambuc }
14911be35a1SLionel Sambuc
ATF_TC_BODY(tanhf_inf_pos,tc)15011be35a1SLionel Sambuc ATF_TC_BODY(tanhf_inf_pos, tc)
15111be35a1SLionel Sambuc {
15211be35a1SLionel Sambuc const float x = 1.0L / 0.0L;
15311be35a1SLionel Sambuc
15411be35a1SLionel Sambuc ATF_CHECK(tanhf(x) == 1.0);
15511be35a1SLionel Sambuc }
15611be35a1SLionel Sambuc
15711be35a1SLionel Sambuc ATF_TC(tanhf_zero_neg);
ATF_TC_HEAD(tanhf_zero_neg,tc)15811be35a1SLionel Sambuc ATF_TC_HEAD(tanhf_zero_neg, tc)
15911be35a1SLionel Sambuc {
16011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanhf(-0.0) == -0.0");
16111be35a1SLionel Sambuc }
16211be35a1SLionel Sambuc
ATF_TC_BODY(tanhf_zero_neg,tc)16311be35a1SLionel Sambuc ATF_TC_BODY(tanhf_zero_neg, tc)
16411be35a1SLionel Sambuc {
16511be35a1SLionel Sambuc const float x = -0.0L;
16611be35a1SLionel Sambuc float y = tanh(x);
16711be35a1SLionel Sambuc
16811be35a1SLionel Sambuc ATF_CHECK(x == y);
16911be35a1SLionel Sambuc ATF_CHECK(signbit(x) != 0);
17011be35a1SLionel Sambuc
17111be35a1SLionel Sambuc ATF_REQUIRE_MSG(signbit(y) != 0,
17211be35a1SLionel Sambuc "compiler bug, waiting for newer gcc import, see PR lib/44057");
17311be35a1SLionel Sambuc }
17411be35a1SLionel Sambuc
17511be35a1SLionel Sambuc ATF_TC(tanhf_zero_pos);
ATF_TC_HEAD(tanhf_zero_pos,tc)17611be35a1SLionel Sambuc ATF_TC_HEAD(tanhf_zero_pos, tc)
17711be35a1SLionel Sambuc {
17811be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Test tanhf(+0.0) == +0.0");
17911be35a1SLionel Sambuc }
18011be35a1SLionel Sambuc
ATF_TC_BODY(tanhf_zero_pos,tc)18111be35a1SLionel Sambuc ATF_TC_BODY(tanhf_zero_pos, tc)
18211be35a1SLionel Sambuc {
18311be35a1SLionel Sambuc const float x = 0.0L;
18411be35a1SLionel Sambuc float y = tanhf(x);
18511be35a1SLionel Sambuc
18611be35a1SLionel Sambuc ATF_CHECK(x == y);
18711be35a1SLionel Sambuc ATF_CHECK(signbit(x) == 0);
18811be35a1SLionel Sambuc ATF_CHECK(signbit(y) == 0);
18911be35a1SLionel Sambuc }
19011be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)19111be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
19211be35a1SLionel Sambuc {
19311be35a1SLionel Sambuc
19411be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanh_nan);
19511be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanh_inf_neg);
19611be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanh_inf_pos);
19711be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanh_zero_neg);
19811be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanh_zero_pos);
19911be35a1SLionel Sambuc
20011be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanhf_nan);
20111be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanhf_inf_neg);
20211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanhf_inf_pos);
20311be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanhf_zero_neg);
20411be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, tanhf_zero_pos);
20511be35a1SLionel Sambuc
20611be35a1SLionel Sambuc return atf_no_error();
20711be35a1SLionel Sambuc }
208