Remove building with NOCRYPTO option
[minix.git] / tests / lib / libm / t_cos.c
blobd99d60810eeb8b5eb1f14ded5bf25e59f0361c22
1 /* $NetBSD: t_cos.c,v 1.4 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.
32 #include <atf-c.h>
33 #include <math.h>
35 static const struct {
36 int angle;
37 double x;
38 double y;
39 } angles[] = {
40 { -180, -3.141592653589793, -1.0000000000000000 },
41 { -135, -2.356194490192345, -0.7071067811865476 },
42 { -90, -1.570796326794897, 0.0000000000000000 },
43 { -45, -0.785398163397448, 0.7071067811865476 },
44 { 0, 0.000000000000000, 1.0000000000000000 },
45 { 30, 0.523598775598299, 0.8660254037844386 },
46 { 45, 0.785398163397448, 0.7071067811865476 },
47 { 60, 1.047197551196598, 0.5000000000000000 },
48 { 90, 1.570796326794897, 0.0000000000000000 },
49 { 120, 2.094395102393195, -0.5000000000000000 },
50 { 135, 2.356194490192345, -0.7071067811865476 },
51 { 150, 2.617993877991494, -0.8660254037844386 },
52 { 180, 3.141592653589793, -1.0000000000000000 },
53 { 270, 4.712388980384690, 0.0000000000000000 },
54 { 360, 6.283185307179586, 1.0000000000000000 }
58 * cos(3)
60 ATF_TC(cos_angles);
61 ATF_TC_HEAD(cos_angles, tc)
63 atf_tc_set_md_var(tc, "descr", "Test some selected angles");
66 ATF_TC_BODY(cos_angles, tc)
68 const double eps = 1.0e-15;
69 size_t i;
71 for (i = 0; i < __arraycount(angles); i++) {
73 if (fabs(cos(angles[i].x) - angles[i].y) > eps)
74 atf_tc_fail_nonfatal("cos(%d deg) != %0.01f",
75 angles[i].angle, angles[i].y);
79 ATF_TC(cos_nan);
80 ATF_TC_HEAD(cos_nan, tc)
82 atf_tc_set_md_var(tc, "descr", "Test cos(NaN) == NaN");
85 ATF_TC_BODY(cos_nan, tc)
87 const double x = 0.0L / 0.0L;
89 ATF_CHECK(isnan(x) != 0);
90 ATF_CHECK(isnan(cos(x)) != 0);
93 ATF_TC(cos_inf_neg);
94 ATF_TC_HEAD(cos_inf_neg, tc)
96 atf_tc_set_md_var(tc, "descr", "Test cos(-Inf) == NaN");
99 ATF_TC_BODY(cos_inf_neg, tc)
101 const double x = -1.0L / 0.0L;
103 ATF_CHECK(isnan(cos(x)) != 0);
106 ATF_TC(cos_inf_pos);
107 ATF_TC_HEAD(cos_inf_pos, tc)
109 atf_tc_set_md_var(tc, "descr", "Test cos(+Inf) == NaN");
112 ATF_TC_BODY(cos_inf_pos, tc)
114 const double x = 1.0L / 0.0L;
116 ATF_CHECK(isnan(cos(x)) != 0);
120 ATF_TC(cos_zero_neg);
121 ATF_TC_HEAD(cos_zero_neg, tc)
123 atf_tc_set_md_var(tc, "descr", "Test cos(-0.0) == 1.0");
126 ATF_TC_BODY(cos_zero_neg, tc)
128 const double x = -0.0L;
130 ATF_CHECK(cos(x) == 1.0);
133 ATF_TC(cos_zero_pos);
134 ATF_TC_HEAD(cos_zero_pos, tc)
136 atf_tc_set_md_var(tc, "descr", "Test cos(+0.0) == 1.0");
139 ATF_TC_BODY(cos_zero_pos, tc)
141 const double x = 0.0L;
143 ATF_CHECK(cos(x) == 1.0);
147 * cosf(3)
149 ATF_TC(cosf_angles);
150 ATF_TC_HEAD(cosf_angles, tc)
152 atf_tc_set_md_var(tc, "descr", "Test some selected angles");
155 ATF_TC_BODY(cosf_angles, tc)
157 const float eps = 1.0e-7;
158 float x, y;
159 size_t i;
161 for (i = 0; i < __arraycount(angles); i++) {
163 x = angles[i].x;
164 y = angles[i].y;
166 if (fabsf(cosf(x) - y) > eps)
167 atf_tc_fail_nonfatal("cosf(%d deg) != %0.01f",
168 angles[i].angle, angles[i].y);
172 ATF_TC(cosf_nan);
173 ATF_TC_HEAD(cosf_nan, tc)
175 atf_tc_set_md_var(tc, "descr", "Test cosf(NaN) == NaN");
178 ATF_TC_BODY(cosf_nan, tc)
180 const float x = 0.0L / 0.0L;
182 ATF_CHECK(isnan(x) != 0);
183 ATF_CHECK(isnan(cosf(x)) != 0);
186 ATF_TC(cosf_inf_neg);
187 ATF_TC_HEAD(cosf_inf_neg, tc)
189 atf_tc_set_md_var(tc, "descr", "Test cosf(-Inf) == NaN");
192 ATF_TC_BODY(cosf_inf_neg, tc)
194 const float x = -1.0L / 0.0L;
196 if (isnan(cosf(x)) == 0) {
197 atf_tc_expect_fail("PR lib/45362");
198 atf_tc_fail("cosf(-Inf) != NaN");
202 ATF_TC(cosf_inf_pos);
203 ATF_TC_HEAD(cosf_inf_pos, tc)
205 atf_tc_set_md_var(tc, "descr", "Test cosf(+Inf) == NaN");
208 ATF_TC_BODY(cosf_inf_pos, tc)
210 const float x = 1.0L / 0.0L;
212 if (isnan(cosf(x)) == 0) {
213 atf_tc_expect_fail("PR lib/45362");
214 atf_tc_fail("cosf(+Inf) != NaN");
219 ATF_TC(cosf_zero_neg);
220 ATF_TC_HEAD(cosf_zero_neg, tc)
222 atf_tc_set_md_var(tc, "descr", "Test cosf(-0.0) == 1.0");
225 ATF_TC_BODY(cosf_zero_neg, tc)
227 const float x = -0.0L;
229 ATF_CHECK(cosf(x) == 1.0);
232 ATF_TC(cosf_zero_pos);
233 ATF_TC_HEAD(cosf_zero_pos, tc)
235 atf_tc_set_md_var(tc, "descr", "Test cosf(+0.0) == 1.0");
238 ATF_TC_BODY(cosf_zero_pos, tc)
240 const float x = 0.0L;
242 ATF_CHECK(cosf(x) == 1.0);
245 ATF_TP_ADD_TCS(tp)
248 ATF_TP_ADD_TC(tp, cos_angles);
249 ATF_TP_ADD_TC(tp, cos_nan);
250 ATF_TP_ADD_TC(tp, cos_inf_neg);
251 ATF_TP_ADD_TC(tp, cos_inf_pos);
252 ATF_TP_ADD_TC(tp, cos_zero_neg);
253 ATF_TP_ADD_TC(tp, cos_zero_pos);
255 ATF_TP_ADD_TC(tp, cosf_angles);
256 ATF_TP_ADD_TC(tp, cosf_nan);
257 ATF_TP_ADD_TC(tp, cosf_inf_neg);
258 ATF_TP_ADD_TC(tp, cosf_inf_pos);
259 ATF_TP_ADD_TC(tp, cosf_zero_neg);
260 ATF_TP_ADD_TC(tp, cosf_zero_pos);
262 return atf_no_error();