1 /* $NetBSD: t_tanh.c,v 1.6 2011/09/12 17:45:51 jruoho 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.6 2011/09/12 17:45:51 jruoho 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
)
49 const double x
= 0.0L / 0.0L;
51 ATF_CHECK(isnan(x
) != 0);
52 ATF_CHECK(isnan(tanh(x
)) != 0);
57 ATF_TC_HEAD(tanh_inf_neg
, tc
)
59 atf_tc_set_md_var(tc
, "descr", "Test tanh(-Inf) == -1.0");
62 ATF_TC_BODY(tanh_inf_neg
, tc
)
65 const double x
= -1.0L / 0.0L;
67 ATF_CHECK(tanh(x
) == -1.0);
72 ATF_TC_HEAD(tanh_inf_pos
, tc
)
74 atf_tc_set_md_var(tc
, "descr", "Test tanh(+Inf) == +1.0");
77 ATF_TC_BODY(tanh_inf_pos
, tc
)
80 const double x
= 1.0L / 0.0L;
82 ATF_CHECK(tanh(x
) == 1.0);
86 ATF_TC(tanh_zero_neg
);
87 ATF_TC_HEAD(tanh_zero_neg
, tc
)
89 atf_tc_set_md_var(tc
, "descr", "Test tanh(-0.0) == -0.0");
92 ATF_TC_BODY(tanh_zero_neg
, tc
)
95 const double x
= -0.0L;
99 ATF_CHECK(signbit(x
) != 0);
101 ATF_REQUIRE_MSG(signbit(y
) != 0,
102 "compiler bug, waiting for newer gcc import, see PR lib/44057");
106 ATF_TC(tanh_zero_pos
);
107 ATF_TC_HEAD(tanh_zero_pos
, tc
)
109 atf_tc_set_md_var(tc
, "descr", "Test tanh(+0.0) == +0.0");
112 ATF_TC_BODY(tanh_zero_pos
, tc
)
115 const double x
= 0.0L;
119 ATF_CHECK(signbit(x
) == 0);
120 ATF_CHECK(signbit(y
) == 0);
128 ATF_TC_HEAD(tanhf_nan
, tc
)
130 atf_tc_set_md_var(tc
, "descr", "Test tanhf(NaN) == NaN");
133 ATF_TC_BODY(tanhf_nan
, tc
)
136 const float x
= 0.0L / 0.0L;
138 ATF_CHECK(isnan(x
) != 0);
139 ATF_CHECK(isnan(tanhf(x
)) != 0);
143 ATF_TC(tanhf_inf_neg
);
144 ATF_TC_HEAD(tanhf_inf_neg
, tc
)
146 atf_tc_set_md_var(tc
, "descr", "Test tanhf(-Inf) == -1.0");
149 ATF_TC_BODY(tanhf_inf_neg
, tc
)
152 const float x
= -1.0L / 0.0L;
154 ATF_CHECK(tanhf(x
) == -1.0);
158 ATF_TC(tanhf_inf_pos
);
159 ATF_TC_HEAD(tanhf_inf_pos
, tc
)
161 atf_tc_set_md_var(tc
, "descr", "Test tanhf(+Inf) == +1.0");
164 ATF_TC_BODY(tanhf_inf_pos
, tc
)
167 const float x
= 1.0L / 0.0L;
169 ATF_CHECK(tanhf(x
) == 1.0);
173 ATF_TC(tanhf_zero_neg
);
174 ATF_TC_HEAD(tanhf_zero_neg
, tc
)
176 atf_tc_set_md_var(tc
, "descr", "Test tanhf(-0.0) == -0.0");
179 ATF_TC_BODY(tanhf_zero_neg
, tc
)
182 const float x
= -0.0L;
186 ATF_CHECK(signbit(x
) != 0);
188 ATF_REQUIRE_MSG(signbit(y
) != 0,
189 "compiler bug, waiting for newer gcc import, see PR lib/44057");
193 ATF_TC(tanhf_zero_pos
);
194 ATF_TC_HEAD(tanhf_zero_pos
, tc
)
196 atf_tc_set_md_var(tc
, "descr", "Test tanhf(+0.0) == +0.0");
199 ATF_TC_BODY(tanhf_zero_pos
, tc
)
202 const float x
= 0.0L;
206 ATF_CHECK(signbit(x
) == 0);
207 ATF_CHECK(signbit(y
) == 0);
214 ATF_TP_ADD_TC(tp
, tanh_nan
);
215 ATF_TP_ADD_TC(tp
, tanh_inf_neg
);
216 ATF_TP_ADD_TC(tp
, tanh_inf_pos
);
217 ATF_TP_ADD_TC(tp
, tanh_zero_neg
);
218 ATF_TP_ADD_TC(tp
, tanh_zero_pos
);
220 ATF_TP_ADD_TC(tp
, tanhf_nan
);
221 ATF_TP_ADD_TC(tp
, tanhf_inf_neg
);
222 ATF_TP_ADD_TC(tp
, tanhf_inf_pos
);
223 ATF_TP_ADD_TC(tp
, tanhf_zero_neg
);
224 ATF_TP_ADD_TC(tp
, tanhf_zero_pos
);
226 return atf_no_error();