1 /* $NetBSD: t_cosh.c,v 1.5 2013/04/09 12:11:04 isaki 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_cosh.c,v 1.5 2013/04/09 12:11:04 isaki Exp $");
43 { -10, 11013.23292010332, 1e4
, },
44 { -2, 3.762195691083631, 1, },
45 { -1, 1.543080634815244, 1, },
46 { -0.05, 1.001250260438369, 1, },
47 { -0.001, 1.000000500000042, 1, },
49 { 0.001, 1.000000500000042, 1, },
50 { 0.05, 1.001250260438369, 1, },
51 { 1, 1.543080634815244, 1, },
52 { 2, 3.762195691083631, 1, },
53 { 10, 11013.23292010332, 1e4
, },
60 ATF_TC_HEAD(cosh_inrange
, tc
)
62 atf_tc_set_md_var(tc
, "descr", "cosh(x) for some values");
65 ATF_TC_BODY(cosh_inrange
, tc
)
73 for (i
= 0; i
< __arraycount(values
); i
++) {
76 eps
= 1e-15 * values
[i
].e
;
78 if (fabs(cosh(x
) - y
) > eps
)
79 atf_tc_fail_nonfatal("cosh(%g) != %g\n", x
, y
);
85 ATF_TC_HEAD(cosh_nan
, tc
)
87 atf_tc_set_md_var(tc
, "descr", "Test cosh(NaN) == NaN");
90 ATF_TC_BODY(cosh_nan
, tc
)
93 const double x
= 0.0L / 0.0L;
95 ATF_CHECK(isnan(x
) != 0);
96 ATF_CHECK(isnan(cosh(x
)) != 0);
100 ATF_TC(cosh_inf_neg
);
101 ATF_TC_HEAD(cosh_inf_neg
, tc
)
103 atf_tc_set_md_var(tc
, "descr", "Test cosh(-Inf) == +Inf");
106 ATF_TC_BODY(cosh_inf_neg
, tc
)
109 const double x
= -1.0L / 0.0L;
112 ATF_CHECK(isinf(y
) != 0);
113 ATF_CHECK(signbit(y
) == 0);
117 ATF_TC(cosh_inf_pos
);
118 ATF_TC_HEAD(cosh_inf_pos
, tc
)
120 atf_tc_set_md_var(tc
, "descr", "Test cosh(+Inf) == +Inf");
123 ATF_TC_BODY(cosh_inf_pos
, tc
)
126 const double x
= 1.0L / 0.0L;
129 ATF_CHECK(isinf(y
) != 0);
130 ATF_CHECK(signbit(y
) == 0);
134 ATF_TC(cosh_zero_neg
);
135 ATF_TC_HEAD(cosh_zero_neg
, tc
)
137 atf_tc_set_md_var(tc
, "descr", "Test cosh(-0.0) == 1.0");
140 ATF_TC_BODY(cosh_zero_neg
, tc
)
143 const double x
= -0.0L;
146 atf_tc_fail_nonfatal("cosh(-0.0) != 1.0");
150 ATF_TC(cosh_zero_pos
);
151 ATF_TC_HEAD(cosh_zero_pos
, tc
)
153 atf_tc_set_md_var(tc
, "descr", "Test cosh(+0.0) == 1.0");
156 ATF_TC_BODY(cosh_zero_pos
, tc
)
159 const double x
= 0.0L;
162 atf_tc_fail_nonfatal("cosh(+0.0) != 1.0");
169 ATF_TC(coshf_inrange
);
170 ATF_TC_HEAD(coshf_inrange
, tc
)
172 atf_tc_set_md_var(tc
, "descr", "coshf(x) for some values");
175 ATF_TC_BODY(coshf_inrange
, tc
)
183 for (i
= 0; i
< __arraycount(values
); i
++) {
186 eps
= 1e-6 * values
[i
].e
;
188 if (fabsf(coshf(x
) - y
) > eps
)
189 atf_tc_fail_nonfatal("coshf(%g) != %g\n", x
, y
);
195 ATF_TC_HEAD(coshf_nan
, tc
)
197 atf_tc_set_md_var(tc
, "descr", "Test coshf(NaN) == NaN");
200 ATF_TC_BODY(coshf_nan
, tc
)
203 const float x
= 0.0L / 0.0L;
205 ATF_CHECK(isnan(x
) != 0);
206 ATF_CHECK(isnan(coshf(x
)) != 0);
210 ATF_TC(coshf_inf_neg
);
211 ATF_TC_HEAD(coshf_inf_neg
, tc
)
213 atf_tc_set_md_var(tc
, "descr", "Test coshf(-Inf) == +Inf");
216 ATF_TC_BODY(coshf_inf_neg
, tc
)
219 const float x
= -1.0L / 0.0L;
222 ATF_CHECK(isinf(y
) != 0);
223 ATF_CHECK(signbit(y
) == 0);
227 ATF_TC(coshf_inf_pos
);
228 ATF_TC_HEAD(coshf_inf_pos
, tc
)
230 atf_tc_set_md_var(tc
, "descr", "Test coshf(+Inf) == +Inf");
233 ATF_TC_BODY(coshf_inf_pos
, tc
)
236 const float x
= 1.0L / 0.0L;
239 ATF_CHECK(isinf(y
) != 0);
240 ATF_CHECK(signbit(y
) == 0);
244 ATF_TC(coshf_zero_neg
);
245 ATF_TC_HEAD(coshf_zero_neg
, tc
)
247 atf_tc_set_md_var(tc
, "descr", "Test coshf(-0.0) == 1.0");
250 ATF_TC_BODY(coshf_zero_neg
, tc
)
253 const float x
= -0.0L;
256 atf_tc_fail_nonfatal("coshf(-0.0) != 1.0");
260 ATF_TC(coshf_zero_pos
);
261 ATF_TC_HEAD(coshf_zero_pos
, tc
)
263 atf_tc_set_md_var(tc
, "descr", "Test coshf(+0.0) == 1.0");
266 ATF_TC_BODY(coshf_zero_pos
, tc
)
269 const float x
= 0.0L;
272 atf_tc_fail_nonfatal("coshf(+0.0) != 1.0");
279 ATF_TP_ADD_TC(tp
, cosh_inrange
);
280 ATF_TP_ADD_TC(tp
, cosh_nan
);
281 ATF_TP_ADD_TC(tp
, cosh_inf_neg
);
282 ATF_TP_ADD_TC(tp
, cosh_inf_pos
);
283 ATF_TP_ADD_TC(tp
, cosh_zero_neg
);
284 ATF_TP_ADD_TC(tp
, cosh_zero_pos
);
286 ATF_TP_ADD_TC(tp
, coshf_inrange
);
287 ATF_TP_ADD_TC(tp
, coshf_nan
);
288 ATF_TP_ADD_TC(tp
, coshf_inf_neg
);
289 ATF_TP_ADD_TC(tp
, coshf_inf_pos
);
290 ATF_TP_ADD_TC(tp
, coshf_zero_neg
);
291 ATF_TP_ADD_TC(tp
, coshf_zero_pos
);
293 return atf_no_error();