Remove building with NOCRYPTO option
[minix.git] / tests / lib / libm / t_cosh.c
blob3f998de761bb20106045f7d357d89854b8fb9d34
1 /* $NetBSD: t_cosh.c,v 1.6 2014/03/03 10:39:08 martin 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.6 2014/03/03 10:39:08 martin 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 double eps;
68 double x;
69 double y;
70 size_t i;
72 for (i = 0; i < __arraycount(values); i++) {
73 x = values[i].x;
74 y = values[i].y;
75 eps = 1e-15 * values[i].e;
77 if (fabs(cosh(x) - y) > eps)
78 atf_tc_fail_nonfatal("cosh(%g) != %g\n", x, y);
82 ATF_TC(cosh_nan);
83 ATF_TC_HEAD(cosh_nan, tc)
85 atf_tc_set_md_var(tc, "descr", "Test cosh(NaN) == NaN");
88 ATF_TC_BODY(cosh_nan, tc)
90 const double x = 0.0L / 0.0L;
92 ATF_CHECK(isnan(x) != 0);
93 ATF_CHECK(isnan(cosh(x)) != 0);
96 ATF_TC(cosh_inf_neg);
97 ATF_TC_HEAD(cosh_inf_neg, tc)
99 atf_tc_set_md_var(tc, "descr", "Test cosh(-Inf) == +Inf");
102 ATF_TC_BODY(cosh_inf_neg, tc)
104 const double x = -1.0L / 0.0L;
105 double y = cosh(x);
107 ATF_CHECK(isinf(y) != 0);
108 ATF_CHECK(signbit(y) == 0);
111 ATF_TC(cosh_inf_pos);
112 ATF_TC_HEAD(cosh_inf_pos, tc)
114 atf_tc_set_md_var(tc, "descr", "Test cosh(+Inf) == +Inf");
117 ATF_TC_BODY(cosh_inf_pos, tc)
119 const double x = 1.0L / 0.0L;
120 double y = cosh(x);
122 ATF_CHECK(isinf(y) != 0);
123 ATF_CHECK(signbit(y) == 0);
126 ATF_TC(cosh_zero_neg);
127 ATF_TC_HEAD(cosh_zero_neg, tc)
129 atf_tc_set_md_var(tc, "descr", "Test cosh(-0.0) == 1.0");
132 ATF_TC_BODY(cosh_zero_neg, tc)
134 const double x = -0.0L;
136 if (cosh(x) != 1.0)
137 atf_tc_fail_nonfatal("cosh(-0.0) != 1.0");
140 ATF_TC(cosh_zero_pos);
141 ATF_TC_HEAD(cosh_zero_pos, tc)
143 atf_tc_set_md_var(tc, "descr", "Test cosh(+0.0) == 1.0");
146 ATF_TC_BODY(cosh_zero_pos, tc)
148 const double x = 0.0L;
150 if (cosh(x) != 1.0)
151 atf_tc_fail_nonfatal("cosh(+0.0) != 1.0");
155 * coshf(3)
157 ATF_TC(coshf_inrange);
158 ATF_TC_HEAD(coshf_inrange, tc)
160 atf_tc_set_md_var(tc, "descr", "coshf(x) for some values");
163 ATF_TC_BODY(coshf_inrange, tc)
165 float eps;
166 float x;
167 float y;
168 size_t i;
170 for (i = 0; i < __arraycount(values); i++) {
171 x = values[i].x;
172 y = values[i].y;
173 eps = 1e-6 * values[i].e;
175 if (fabsf(coshf(x) - y) > eps)
176 atf_tc_fail_nonfatal("coshf(%g) != %g\n", x, y);
180 ATF_TC(coshf_nan);
181 ATF_TC_HEAD(coshf_nan, tc)
183 atf_tc_set_md_var(tc, "descr", "Test coshf(NaN) == NaN");
186 ATF_TC_BODY(coshf_nan, tc)
188 const float x = 0.0L / 0.0L;
190 ATF_CHECK(isnan(x) != 0);
191 ATF_CHECK(isnan(coshf(x)) != 0);
194 ATF_TC(coshf_inf_neg);
195 ATF_TC_HEAD(coshf_inf_neg, tc)
197 atf_tc_set_md_var(tc, "descr", "Test coshf(-Inf) == +Inf");
200 ATF_TC_BODY(coshf_inf_neg, tc)
202 const float x = -1.0L / 0.0L;
203 float y = coshf(x);
205 ATF_CHECK(isinf(y) != 0);
206 ATF_CHECK(signbit(y) == 0);
209 ATF_TC(coshf_inf_pos);
210 ATF_TC_HEAD(coshf_inf_pos, tc)
212 atf_tc_set_md_var(tc, "descr", "Test coshf(+Inf) == +Inf");
215 ATF_TC_BODY(coshf_inf_pos, tc)
217 const float x = 1.0L / 0.0L;
218 float y = coshf(x);
220 ATF_CHECK(isinf(y) != 0);
221 ATF_CHECK(signbit(y) == 0);
224 ATF_TC(coshf_zero_neg);
225 ATF_TC_HEAD(coshf_zero_neg, tc)
227 atf_tc_set_md_var(tc, "descr", "Test coshf(-0.0) == 1.0");
230 ATF_TC_BODY(coshf_zero_neg, tc)
232 const float x = -0.0L;
234 if (coshf(x) != 1.0)
235 atf_tc_fail_nonfatal("coshf(-0.0) != 1.0");
238 ATF_TC(coshf_zero_pos);
239 ATF_TC_HEAD(coshf_zero_pos, tc)
241 atf_tc_set_md_var(tc, "descr", "Test coshf(+0.0) == 1.0");
244 ATF_TC_BODY(coshf_zero_pos, tc)
246 const float x = 0.0L;
248 if (coshf(x) != 1.0)
249 atf_tc_fail_nonfatal("coshf(+0.0) != 1.0");
252 ATF_TP_ADD_TCS(tp)
255 ATF_TP_ADD_TC(tp, cosh_inrange);
256 ATF_TP_ADD_TC(tp, cosh_nan);
257 ATF_TP_ADD_TC(tp, cosh_inf_neg);
258 ATF_TP_ADD_TC(tp, cosh_inf_pos);
259 ATF_TP_ADD_TC(tp, cosh_zero_neg);
260 ATF_TP_ADD_TC(tp, cosh_zero_pos);
262 ATF_TP_ADD_TC(tp, coshf_inrange);
263 ATF_TP_ADD_TC(tp, coshf_nan);
264 ATF_TP_ADD_TC(tp, coshf_inf_neg);
265 ATF_TP_ADD_TC(tp, coshf_inf_pos);
266 ATF_TP_ADD_TC(tp, coshf_zero_neg);
267 ATF_TP_ADD_TC(tp, coshf_zero_pos);
269 return atf_no_error();