t_tanh.c revision 272345
145095Ssos/* $NetBSD: t_tanh.c,v 1.7 2014/03/03 10:39:08 martin Exp $ */ 245095Ssos 345095Ssos/*- 445095Ssos * Copyright (c) 2011 The NetBSD Foundation, Inc. 545095Ssos * All rights reserved. 645095Ssos * 745095Ssos * This code is derived from software contributed to The NetBSD Foundation 845095Ssos * by Jukka Ruohonen. 945095Ssos * 1045095Ssos * Redistribution and use in source and binary forms, with or without 1145095Ssos * modification, are permitted provided that the following conditions 1245095Ssos * are met: 1345095Ssos * 1. Redistributions of source code must retain the above copyright 1445095Ssos * notice, this list of conditions and the following disclaimer. 1545095Ssos * 2. Redistributions in binary form must reproduce the above copyright 1645095Ssos * notice, this list of conditions and the following disclaimer in the 1745095Ssos * documentation and/or other materials provided with the distribution. 1845095Ssos * 1945095Ssos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2045095Ssos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2145095Ssos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2245095Ssos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2345095Ssos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2445095Ssos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2545095Ssos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2645095Ssos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2745095Ssos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2850477Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2945095Ssos * POSSIBILITY OF SUCH DAMAGE. 3045095Ssos */ 3145150Ssos#include <sys/cdefs.h> 3251520Ssos__RCSID("$NetBSD: t_tanh.c,v 1.7 2014/03/03 10:39:08 martin Exp $"); 3345095Ssos 3445095Ssos#include <atf-c.h> 3545095Ssos#include <math.h> 3645095Ssos 3745798Ssos/* 3851520Ssos * tanh(3) 3945095Ssos */ 4047272SsosATF_TC(tanh_nan); 4145095SsosATF_TC_HEAD(tanh_nan, tc) 4247272Ssos{ 4351520Ssos atf_tc_set_md_var(tc, "descr", "Test tanh(NaN) == NaN"); 4451520Ssos} 4551520Ssos 4645095SsosATF_TC_BODY(tanh_nan, tc) 4745095Ssos{ 4852067Ssos const double x = 0.0L / 0.0L; 4952067Ssos 5052067Ssos ATF_CHECK(isnan(x) != 0); 5152067Ssos ATF_CHECK(isnan(tanh(x)) != 0); 5252067Ssos} 5345720Speter 5445720SpeterATF_TC(tanh_inf_neg); 5551520SsosATF_TC_HEAD(tanh_inf_neg, tc) 5645720Speter{ 5745720Speter atf_tc_set_md_var(tc, "descr", "Test tanh(-Inf) == -1.0"); 5845150Ssos} 5945150Ssos 6045095SsosATF_TC_BODY(tanh_inf_neg, tc) 6145095Ssos{ 6245095Ssos const double x = -1.0L / 0.0L; 6345095Ssos 6445095Ssos ATF_CHECK(tanh(x) == -1.0); 6545095Ssos} 6645095Ssos 6745095SsosATF_TC(tanh_inf_pos); 6845095SsosATF_TC_HEAD(tanh_inf_pos, tc) 6951520Ssos{ 7045095Ssos atf_tc_set_md_var(tc, "descr", "Test tanh(+Inf) == +1.0"); 7145095Ssos} 7245095Ssos 7345095SsosATF_TC_BODY(tanh_inf_pos, tc) 7452067Ssos{ 7552067Ssos const double x = 1.0L / 0.0L; 7652067Ssos 7752067Ssos ATF_CHECK(tanh(x) == 1.0); 7852067Ssos} 7952067Ssos 8052067SsosATF_TC(tanh_zero_neg); 8152067SsosATF_TC_HEAD(tanh_zero_neg, tc) 8252067Ssos{ 8352067Ssos atf_tc_set_md_var(tc, "descr", "Test tanh(-0.0) == -0.0"); 8452067Ssos} 8545095Ssos 8651520SsosATF_TC_BODY(tanh_zero_neg, tc) 8745095Ssos{ 8845798Ssos const double x = -0.0L; 8945798Ssos double y = tanh(x); 9051520Ssos 9151520Ssos ATF_CHECK(x == y); 9251520Ssos ATF_CHECK(signbit(x) != 0); 9345095Ssos 9451520Ssos ATF_REQUIRE_MSG(signbit(y) != 0, 9545095Ssos "compiler bug, waiting for newer gcc import, see PR lib/44057"); 9651520Ssos} 9745095Ssos 9845095SsosATF_TC(tanh_zero_pos); 9945095SsosATF_TC_HEAD(tanh_zero_pos, tc) 10051520Ssos{ 10145095Ssos atf_tc_set_md_var(tc, "descr", "Test tanh(+0.0) == +0.0"); 10245095Ssos} 10353029Ssos 10451520SsosATF_TC_BODY(tanh_zero_pos, tc) 10551520Ssos{ 10651520Ssos const double x = 0.0L; 10751520Ssos double y = tanh(x); 10853681Ssos 10953681Ssos ATF_CHECK(x == y); 11053681Ssos ATF_CHECK(signbit(x) == 0); 11153681Ssos ATF_CHECK(signbit(y) == 0); 11253681Ssos} 11353681Ssos 11453681Ssos/* 11553681Ssos * tanhf(3) 11653681Ssos */ 11753681SsosATF_TC(tanhf_nan); 11845095SsosATF_TC_HEAD(tanhf_nan, tc) 11945095Ssos{ 12045095Ssos atf_tc_set_md_var(tc, "descr", "Test tanhf(NaN) == NaN"); 12145095Ssos} 12245095Ssos 12345095SsosATF_TC_BODY(tanhf_nan, tc) 12445095Ssos{ 12545095Ssos const float x = 0.0L / 0.0L; 12645798Ssos 12751520Ssos ATF_CHECK(isnan(x) != 0); 12851520Ssos ATF_CHECK(isnan(tanhf(x)) != 0); 12951520Ssos} 13051520Ssos 13151520SsosATF_TC(tanhf_inf_neg); 13251520SsosATF_TC_HEAD(tanhf_inf_neg, tc) 13351520Ssos{ 13451520Ssos atf_tc_set_md_var(tc, "descr", "Test tanhf(-Inf) == -1.0"); 13551520Ssos} 13651520Ssos 13751520SsosATF_TC_BODY(tanhf_inf_neg, tc) 13851520Ssos{ 13951520Ssos const float x = -1.0L / 0.0L; 14045095Ssos 14145095Ssos ATF_CHECK(tanhf(x) == -1.0); 14253029Ssos} 14351520Ssos 14451520SsosATF_TC(tanhf_inf_pos); 14551520SsosATF_TC_HEAD(tanhf_inf_pos, tc) 14651520Ssos{ 14753681Ssos atf_tc_set_md_var(tc, "descr", "Test tanhf(+Inf) == +1.0"); 14853681Ssos} 14953681Ssos 15053681SsosATF_TC_BODY(tanhf_inf_pos, tc) 15153681Ssos{ 15253681Ssos const float x = 1.0L / 0.0L; 15353681Ssos 15453681Ssos ATF_CHECK(tanhf(x) == 1.0); 15553681Ssos} 15653681Ssos 15753681SsosATF_TC(tanhf_zero_neg); 15853681SsosATF_TC_HEAD(tanhf_zero_neg, tc) 15953681Ssos{ 16053681Ssos atf_tc_set_md_var(tc, "descr", "Test tanhf(-0.0) == -0.0"); 16153681Ssos} 16253681Ssos 16353681SsosATF_TC_BODY(tanhf_zero_neg, tc) 16453681Ssos{ 16553681Ssos const float x = -0.0L; 16653681Ssos float y = tanh(x); 16753681Ssos 16853681Ssos ATF_CHECK(x == y); 16953681Ssos ATF_CHECK(signbit(x) != 0); 17053681Ssos 17153681Ssos ATF_REQUIRE_MSG(signbit(y) != 0, 17253681Ssos "compiler bug, waiting for newer gcc import, see PR lib/44057"); 17353681Ssos} 17445095Ssos 17551520SsosATF_TC(tanhf_zero_pos); 17653681SsosATF_TC_HEAD(tanhf_zero_pos, tc) 17745095Ssos{ 17845095Ssos atf_tc_set_md_var(tc, "descr", "Test tanhf(+0.0) == +0.0"); 17945095Ssos} 18045095Ssos 18145095SsosATF_TC_BODY(tanhf_zero_pos, tc) 18245095Ssos{ 18352067Ssos const float x = 0.0L; 18453029Ssos float y = tanhf(x); 18553029Ssos 18653029Ssos ATF_CHECK(x == y); 18753029Ssos ATF_CHECK(signbit(x) == 0); 18853029Ssos ATF_CHECK(signbit(y) == 0); 18952067Ssos} 19053681Ssos 19152067SsosATF_TP_ADD_TCS(tp) 19252067Ssos{ 19351520Ssos 19453029Ssos ATF_TP_ADD_TC(tp, tanh_nan); 19551520Ssos ATF_TP_ADD_TC(tp, tanh_inf_neg); 19652067Ssos ATF_TP_ADD_TC(tp, tanh_inf_pos); 19751520Ssos ATF_TP_ADD_TC(tp, tanh_zero_neg); 19851520Ssos ATF_TP_ADD_TC(tp, tanh_zero_pos); 19953681Ssos 20053681Ssos ATF_TP_ADD_TC(tp, tanhf_nan); 20153681Ssos ATF_TP_ADD_TC(tp, tanhf_inf_neg); 20253681Ssos ATF_TP_ADD_TC(tp, tanhf_inf_pos); 20353681Ssos ATF_TP_ADD_TC(tp, tanhf_zero_neg); 20453681Ssos ATF_TP_ADD_TC(tp, tanhf_zero_pos); 20553681Ssos 20653681Ssos return atf_no_error(); 20753681Ssos} 20853681Ssos