1 /* $NetBSD: t_tanh.c,v 1.7 2014/03/03 10:39:08 martin Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_tanh.c,v 1.7 2014/03/03 10:39:08 martin Exp $");
41 ATF_TC_HEAD(tanh_nan
, tc
)
43 atf_tc_set_md_var(tc
, "descr", "Test tanh(NaN) == NaN");
46 ATF_TC_BODY(tanh_nan
, tc
)
48 const double x
= 0.0L / 0.0L;
50 ATF_CHECK(isnan(x
) != 0);
51 ATF_CHECK(isnan(tanh(x
)) != 0);
55 ATF_TC_HEAD(tanh_inf_neg
, tc
)
57 atf_tc_set_md_var(tc
, "descr", "Test tanh(-Inf) == -1.0");
60 ATF_TC_BODY(tanh_inf_neg
, tc
)
62 const double x
= -1.0L / 0.0L;
64 ATF_CHECK(tanh(x
) == -1.0);
68 ATF_TC_HEAD(tanh_inf_pos
, tc
)
70 atf_tc_set_md_var(tc
, "descr", "Test tanh(+Inf) == +1.0");
73 ATF_TC_BODY(tanh_inf_pos
, tc
)
75 const double x
= 1.0L / 0.0L;
77 ATF_CHECK(tanh(x
) == 1.0);
80 ATF_TC(tanh_zero_neg
);
81 ATF_TC_HEAD(tanh_zero_neg
, tc
)
83 atf_tc_set_md_var(tc
, "descr", "Test tanh(-0.0) == -0.0");
86 ATF_TC_BODY(tanh_zero_neg
, tc
)
88 const double x
= -0.0L;
92 ATF_CHECK(signbit(x
) != 0);
94 ATF_REQUIRE_MSG(signbit(y
) != 0,
95 "compiler bug, waiting for newer gcc import, see PR lib/44057");
98 ATF_TC(tanh_zero_pos
);
99 ATF_TC_HEAD(tanh_zero_pos
, tc
)
101 atf_tc_set_md_var(tc
, "descr", "Test tanh(+0.0) == +0.0");
104 ATF_TC_BODY(tanh_zero_pos
, tc
)
106 const double x
= 0.0L;
110 ATF_CHECK(signbit(x
) == 0);
111 ATF_CHECK(signbit(y
) == 0);
118 ATF_TC_HEAD(tanhf_nan
, tc
)
120 atf_tc_set_md_var(tc
, "descr", "Test tanhf(NaN) == NaN");
123 ATF_TC_BODY(tanhf_nan
, tc
)
125 const float x
= 0.0L / 0.0L;
127 ATF_CHECK(isnan(x
) != 0);
128 ATF_CHECK(isnan(tanhf(x
)) != 0);
131 ATF_TC(tanhf_inf_neg
);
132 ATF_TC_HEAD(tanhf_inf_neg
, tc
)
134 atf_tc_set_md_var(tc
, "descr", "Test tanhf(-Inf) == -1.0");
137 ATF_TC_BODY(tanhf_inf_neg
, tc
)
139 const float x
= -1.0L / 0.0L;
141 ATF_CHECK(tanhf(x
) == -1.0);
144 ATF_TC(tanhf_inf_pos
);
145 ATF_TC_HEAD(tanhf_inf_pos
, tc
)
147 atf_tc_set_md_var(tc
, "descr", "Test tanhf(+Inf) == +1.0");
150 ATF_TC_BODY(tanhf_inf_pos
, tc
)
152 const float x
= 1.0L / 0.0L;
154 ATF_CHECK(tanhf(x
) == 1.0);
157 ATF_TC(tanhf_zero_neg
);
158 ATF_TC_HEAD(tanhf_zero_neg
, tc
)
160 atf_tc_set_md_var(tc
, "descr", "Test tanhf(-0.0) == -0.0");
163 ATF_TC_BODY(tanhf_zero_neg
, tc
)
165 const float x
= -0.0L;
169 ATF_CHECK(signbit(x
) != 0);
171 ATF_REQUIRE_MSG(signbit(y
) != 0,
172 "compiler bug, waiting for newer gcc import, see PR lib/44057");
175 ATF_TC(tanhf_zero_pos
);
176 ATF_TC_HEAD(tanhf_zero_pos
, tc
)
178 atf_tc_set_md_var(tc
, "descr", "Test tanhf(+0.0) == +0.0");
181 ATF_TC_BODY(tanhf_zero_pos
, tc
)
183 const float x
= 0.0L;
187 ATF_CHECK(signbit(x
) == 0);
188 ATF_CHECK(signbit(y
) == 0);
194 ATF_TP_ADD_TC(tp
, tanh_nan
);
195 ATF_TP_ADD_TC(tp
, tanh_inf_neg
);
196 ATF_TP_ADD_TC(tp
, tanh_inf_pos
);
197 ATF_TP_ADD_TC(tp
, tanh_zero_neg
);
198 ATF_TP_ADD_TC(tp
, tanh_zero_pos
);
200 ATF_TP_ADD_TC(tp
, tanhf_nan
);
201 ATF_TP_ADD_TC(tp
, tanhf_inf_neg
);
202 ATF_TP_ADD_TC(tp
, tanhf_inf_pos
);
203 ATF_TP_ADD_TC(tp
, tanhf_zero_neg
);
204 ATF_TP_ADD_TC(tp
, tanhf_zero_pos
);
206 return atf_no_error();