t_tan.c revision 1.1 1 /* $NetBSD: t_tan.c,v 1.1 2011/09/14 05:18:19 jruoho Exp $ */
2
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jukka Ruohonen.
9 *
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.
18 *
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.
30 */
31
32 #include <atf-c.h>
33 #include <math.h>
34
35 static const struct {
36 int angle;
37 double x;
38 double y;
39 } angles[] = {
40 { -180, -3.141592653589793, 0.0000000000000000 },
41 { -135, -2.356194490192345, 1.0000000000000000 },
42 { -45, -0.785398163397448, -1.0000000000000000 },
43 { 0, 0.000000000000000, 0.0000000000000000 },
44 { 30, 0.523598775598299, 0.5773502691896258 },
45 { 45, 0.785398163397448, 1.0000000000000000 },
46 { 60, 1.047197551196598, 1.7320508075688773 },
47 { 120, 2.094395102393195, -1.7320508075688773 },
48 { 135, 2.356194490192345, -1.0000000000000000 },
49 { 150, 2.617993877991494, -0.5773502691896258 },
50 { 180, 3.141592653589793, 0.0000000000000000 },
51 { 360, 6.283185307179586, 0.0000000000000000 }
52 };
53
54 /*
55 * tan(3)
56 */
57 ATF_TC(tan_angles);
58 ATF_TC_HEAD(tan_angles, tc)
59 {
60 atf_tc_set_md_var(tc, "descr", "Test some selected angles");
61 }
62
63 ATF_TC_BODY(tan_angles, tc)
64 {
65 const double eps = 1.0e-14;
66 size_t i;
67
68 for (i = 0; i < __arraycount(angles); i++) {
69
70 if (fabs(tan(angles[i].x) - angles[i].y) > eps)
71 atf_tc_fail_nonfatal("tan(%d deg) != %0.01f",
72 angles[i].angle, angles[i].y);
73 }
74 }
75
76 ATF_TC(tan_nan);
77 ATF_TC_HEAD(tan_nan, tc)
78 {
79 atf_tc_set_md_var(tc, "descr", "Test tan(NaN) == NaN");
80 }
81
82 ATF_TC_BODY(tan_nan, tc)
83 {
84 #ifndef __vax__
85 const double x = 0.0L / 0.0L;
86
87 ATF_CHECK(isnan(x) != 0);
88 ATF_CHECK(isnan(tan(x)) != 0);
89 #endif
90 }
91
92 ATF_TC(tan_inf_neg);
93 ATF_TC_HEAD(tan_inf_neg, tc)
94 {
95 atf_tc_set_md_var(tc, "descr", "Test tan(-Inf) == NaN");
96 }
97
98 ATF_TC_BODY(tan_inf_neg, tc)
99 {
100 #ifndef __vax__
101 const double x = -1.0L / 0.0L;
102
103 ATF_CHECK(isnan(tan(x)) != 0);
104 #endif
105 }
106
107 ATF_TC(tan_inf_pos);
108 ATF_TC_HEAD(tan_inf_pos, tc)
109 {
110 atf_tc_set_md_var(tc, "descr", "Test tan(+Inf) == NaN");
111 }
112
113 ATF_TC_BODY(tan_inf_pos, tc)
114 {
115 #ifndef __vax__
116 const double x = 1.0L / 0.0L;
117
118 ATF_CHECK(isnan(tan(x)) != 0);
119 #endif
120 }
121
122
123 ATF_TC(tan_zero_neg);
124 ATF_TC_HEAD(tan_zero_neg, tc)
125 {
126 atf_tc_set_md_var(tc, "descr", "Test tan(-0.0) == -0.0");
127 }
128
129 ATF_TC_BODY(tan_zero_neg, tc)
130 {
131 #ifndef __vax__
132 const double x = -0.0L;
133
134 ATF_CHECK(tan(x) == x);
135 #endif
136 }
137
138 ATF_TC(tan_zero_pos);
139 ATF_TC_HEAD(tan_zero_pos, tc)
140 {
141 atf_tc_set_md_var(tc, "descr", "Test tan(+0.0) == +0.0");
142 }
143
144 ATF_TC_BODY(tan_zero_pos, tc)
145 {
146 #ifndef __vax__
147 const double x = 0.0L;
148
149 ATF_CHECK(tan(x) == x);
150 #endif
151 }
152
153 /*
154 * tanf(3)
155 */
156 ATF_TC(tanf_angles);
157 ATF_TC_HEAD(tanf_angles, tc)
158 {
159 atf_tc_set_md_var(tc, "descr", "Test some selected angles");
160 }
161
162 ATF_TC_BODY(tanf_angles, tc)
163 {
164 const float eps = 1.0e-6;
165 float x, y;
166 size_t i;
167
168 for (i = 0; i < __arraycount(angles); i++) {
169
170 x = angles[i].x;
171 y = angles[i].y;
172
173 if (fabs(tanf(x) - y) > eps)
174 atf_tc_fail_nonfatal("tanf(%d deg) != %0.01f",
175 angles[i].angle, angles[i].y);
176 }
177 }
178
179 ATF_TC(tanf_nan);
180 ATF_TC_HEAD(tanf_nan, tc)
181 {
182 atf_tc_set_md_var(tc, "descr", "Test tanf(NaN) == NaN");
183 }
184
185 ATF_TC_BODY(tanf_nan, tc)
186 {
187 #ifndef __vax__
188 const float x = 0.0L / 0.0L;
189
190 ATF_CHECK(isnan(x) != 0);
191 ATF_CHECK(isnan(tanf(x)) != 0);
192 #endif
193 }
194
195 ATF_TC(tanf_inf_neg);
196 ATF_TC_HEAD(tanf_inf_neg, tc)
197 {
198 atf_tc_set_md_var(tc, "descr", "Test tanf(-Inf) == NaN");
199 }
200
201 ATF_TC_BODY(tanf_inf_neg, tc)
202 {
203 #ifndef __vax__
204 const float x = -1.0L / 0.0L;
205
206 ATF_CHECK(isnan(tanf(x)) != 0);
207 #endif
208 }
209
210 ATF_TC(tanf_inf_pos);
211 ATF_TC_HEAD(tanf_inf_pos, tc)
212 {
213 atf_tc_set_md_var(tc, "descr", "Test tanf(+Inf) == NaN");
214 }
215
216 ATF_TC_BODY(tanf_inf_pos, tc)
217 {
218 #ifndef __vax__
219 const float x = 1.0L / 0.0L;
220
221 ATF_CHECK(isnan(tanf(x)) != 0);
222 #endif
223 }
224
225
226 ATF_TC(tanf_zero_neg);
227 ATF_TC_HEAD(tanf_zero_neg, tc)
228 {
229 atf_tc_set_md_var(tc, "descr", "Test tanf(-0.0) == -0.0");
230 }
231
232 ATF_TC_BODY(tanf_zero_neg, tc)
233 {
234 #ifndef __vax__
235 const float x = -0.0L;
236
237 ATF_CHECK(tanf(x) == x);
238 #endif
239 }
240
241 ATF_TC(tanf_zero_pos);
242 ATF_TC_HEAD(tanf_zero_pos, tc)
243 {
244 atf_tc_set_md_var(tc, "descr", "Test tanf(+0.0) == +0.0");
245 }
246
247 ATF_TC_BODY(tanf_zero_pos, tc)
248 {
249 #ifndef __vax__
250 const float x = 0.0L;
251
252 ATF_CHECK(tanf(x) == x);
253 #endif
254 }
255
256 ATF_TP_ADD_TCS(tp)
257 {
258
259 ATF_TP_ADD_TC(tp, tan_angles);
260 ATF_TP_ADD_TC(tp, tan_nan);
261 ATF_TP_ADD_TC(tp, tan_inf_neg);
262 ATF_TP_ADD_TC(tp, tan_inf_pos);
263 ATF_TP_ADD_TC(tp, tan_zero_neg);
264 ATF_TP_ADD_TC(tp, tan_zero_pos);
265
266 ATF_TP_ADD_TC(tp, tanf_angles);
267 ATF_TP_ADD_TC(tp, tanf_nan);
268 ATF_TP_ADD_TC(tp, tanf_inf_neg);
269 ATF_TP_ADD_TC(tp, tanf_inf_pos);
270 ATF_TP_ADD_TC(tp, tanf_zero_neg);
271 ATF_TP_ADD_TC(tp, tanf_zero_pos);
272
273 return atf_no_error();
274 }
275