tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libm / t_cosh.c
blob551ec3dbea94c6c6ba554cac2bc5d7ac032a7b5a
1 /* $NetBSD: t_cosh.c,v 1.5 2013/04/09 12:11:04 isaki Exp $ */
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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 $");
34 #include <atf-c.h>
35 #include <math.h>
36 #include <stdio.h>
38 static const struct {
39 double x;
40 double y;
41 double e;
42 } values[] = {
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, },
48 { 0, 1, 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, },
57 * cosh(3)
59 ATF_TC(cosh_inrange);
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)
67 #ifndef __vax__
68 double eps;
69 double x;
70 double y;
71 size_t i;
73 for (i = 0; i < __arraycount(values); i++) {
74 x = values[i].x;
75 y = values[i].y;
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);
81 #endif
84 ATF_TC(cosh_nan);
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)
92 #ifndef __vax__
93 const double x = 0.0L / 0.0L;
95 ATF_CHECK(isnan(x) != 0);
96 ATF_CHECK(isnan(cosh(x)) != 0);
97 #endif
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)
108 #ifndef __vax__
109 const double x = -1.0L / 0.0L;
110 double y = cosh(x);
112 ATF_CHECK(isinf(y) != 0);
113 ATF_CHECK(signbit(y) == 0);
114 #endif
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)
125 #ifndef __vax__
126 const double x = 1.0L / 0.0L;
127 double y = cosh(x);
129 ATF_CHECK(isinf(y) != 0);
130 ATF_CHECK(signbit(y) == 0);
131 #endif
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)
142 #ifndef __vax__
143 const double x = -0.0L;
145 if (cosh(x) != 1.0)
146 atf_tc_fail_nonfatal("cosh(-0.0) != 1.0");
147 #endif
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)
158 #ifndef __vax__
159 const double x = 0.0L;
161 if (cosh(x) != 1.0)
162 atf_tc_fail_nonfatal("cosh(+0.0) != 1.0");
163 #endif
167 * coshf(3)
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)
177 #ifndef __vax__
178 float eps;
179 float x;
180 float y;
181 size_t i;
183 for (i = 0; i < __arraycount(values); i++) {
184 x = values[i].x;
185 y = values[i].y;
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);
191 #endif
194 ATF_TC(coshf_nan);
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)
202 #ifndef __vax__
203 const float x = 0.0L / 0.0L;
205 ATF_CHECK(isnan(x) != 0);
206 ATF_CHECK(isnan(coshf(x)) != 0);
207 #endif
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)
218 #ifndef __vax__
219 const float x = -1.0L / 0.0L;
220 float y = coshf(x);
222 ATF_CHECK(isinf(y) != 0);
223 ATF_CHECK(signbit(y) == 0);
224 #endif
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)
235 #ifndef __vax__
236 const float x = 1.0L / 0.0L;
237 float y = coshf(x);
239 ATF_CHECK(isinf(y) != 0);
240 ATF_CHECK(signbit(y) == 0);
241 #endif
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)
252 #ifndef __vax__
253 const float x = -0.0L;
255 if (coshf(x) != 1.0)
256 atf_tc_fail_nonfatal("coshf(-0.0) != 1.0");
257 #endif
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)
268 #ifndef __vax__
269 const float x = 0.0L;
271 if (coshf(x) != 1.0)
272 atf_tc_fail_nonfatal("coshf(+0.0) != 1.0");
273 #endif
276 ATF_TP_ADD_TCS(tp)
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();