1 /* $NetBSD: t_tan.c,v 1.4 2011/09/15 11:05:50 he 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.
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 }
58 ATF_TC_HEAD(tan_angles
, tc
)
60 atf_tc_set_md_var(tc
, "descr", "Test some selected angles");
63 ATF_TC_BODY(tan_angles
, tc
)
65 const double eps
= 1.0e-14;
68 for (i
= 0; i
< __arraycount(angles
); i
++) {
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
);
77 ATF_TC_HEAD(tan_nan
, tc
)
79 atf_tc_set_md_var(tc
, "descr", "Test tan(NaN) == NaN");
82 ATF_TC_BODY(tan_nan
, tc
)
85 const double x
= 0.0L / 0.0L;
87 ATF_CHECK(isnan(x
) != 0);
88 ATF_CHECK(isnan(tan(x
)) != 0);
93 ATF_TC_HEAD(tan_inf_neg
, tc
)
95 atf_tc_set_md_var(tc
, "descr", "Test tan(-Inf) == NaN");
98 ATF_TC_BODY(tan_inf_neg
, tc
)
101 const double x
= -1.0L / 0.0L;
103 ATF_CHECK(isnan(tan(x
)) != 0);
108 ATF_TC_HEAD(tan_inf_pos
, tc
)
110 atf_tc_set_md_var(tc
, "descr", "Test tan(+Inf) == NaN");
113 ATF_TC_BODY(tan_inf_pos
, tc
)
116 const double x
= 1.0L / 0.0L;
118 ATF_CHECK(isnan(tan(x
)) != 0);
123 ATF_TC(tan_zero_neg
);
124 ATF_TC_HEAD(tan_zero_neg
, tc
)
126 atf_tc_set_md_var(tc
, "descr", "Test tan(-0.0) == -0.0");
129 ATF_TC_BODY(tan_zero_neg
, tc
)
132 const double x
= -0.0L;
134 ATF_CHECK(tan(x
) == x
);
138 ATF_TC(tan_zero_pos
);
139 ATF_TC_HEAD(tan_zero_pos
, tc
)
141 atf_tc_set_md_var(tc
, "descr", "Test tan(+0.0) == +0.0");
144 ATF_TC_BODY(tan_zero_pos
, tc
)
147 const double x
= 0.0L;
149 ATF_CHECK(tan(x
) == x
);
157 ATF_TC_HEAD(tanf_angles
, tc
)
159 atf_tc_set_md_var(tc
, "descr", "Test some selected angles");
162 ATF_TC_BODY(tanf_angles
, tc
)
165 const float eps
= 1.0e-6;
169 for (i
= 0; i
< __arraycount(angles
); i
++) {
174 if (fabsf(tanf(x
) - y
) > eps
)
175 atf_tc_fail_nonfatal("tanf(%d deg) != %0.01f",
176 angles
[i
].angle
, angles
[i
].y
);
182 ATF_TC_HEAD(tanf_nan
, tc
)
184 atf_tc_set_md_var(tc
, "descr", "Test tanf(NaN) == NaN");
187 ATF_TC_BODY(tanf_nan
, tc
)
190 const float x
= 0.0L / 0.0L;
192 ATF_CHECK(isnan(x
) != 0);
193 ATF_CHECK(isnan(tanf(x
)) != 0);
197 ATF_TC(tanf_inf_neg
);
198 ATF_TC_HEAD(tanf_inf_neg
, tc
)
200 atf_tc_set_md_var(tc
, "descr", "Test tanf(-Inf) == NaN");
203 ATF_TC_BODY(tanf_inf_neg
, tc
)
206 const float x
= -1.0L / 0.0L;
208 if (isnan(tanf(x
)) == 0) {
209 atf_tc_expect_fail("PR lib/45362");
210 atf_tc_fail("tanf(-Inf) != NaN");
215 ATF_TC(tanf_inf_pos
);
216 ATF_TC_HEAD(tanf_inf_pos
, tc
)
218 atf_tc_set_md_var(tc
, "descr", "Test tanf(+Inf) == NaN");
221 ATF_TC_BODY(tanf_inf_pos
, tc
)
224 const float x
= 1.0L / 0.0L;
226 if (isnan(tanf(x
)) == 0) {
227 atf_tc_expect_fail("PR lib/45362");
228 atf_tc_fail("tanf(+Inf) != NaN");
234 ATF_TC(tanf_zero_neg
);
235 ATF_TC_HEAD(tanf_zero_neg
, tc
)
237 atf_tc_set_md_var(tc
, "descr", "Test tanf(-0.0) == -0.0");
240 ATF_TC_BODY(tanf_zero_neg
, tc
)
243 const float x
= -0.0L;
245 ATF_CHECK(tanf(x
) == x
);
249 ATF_TC(tanf_zero_pos
);
250 ATF_TC_HEAD(tanf_zero_pos
, tc
)
252 atf_tc_set_md_var(tc
, "descr", "Test tanf(+0.0) == +0.0");
255 ATF_TC_BODY(tanf_zero_pos
, tc
)
258 const float x
= 0.0L;
260 ATF_CHECK(tanf(x
) == x
);
267 ATF_TP_ADD_TC(tp
, tan_angles
);
268 ATF_TP_ADD_TC(tp
, tan_nan
);
269 ATF_TP_ADD_TC(tp
, tan_inf_neg
);
270 ATF_TP_ADD_TC(tp
, tan_inf_pos
);
271 ATF_TP_ADD_TC(tp
, tan_zero_neg
);
272 ATF_TP_ADD_TC(tp
, tan_zero_pos
);
274 ATF_TP_ADD_TC(tp
, tanf_angles
);
275 ATF_TP_ADD_TC(tp
, tanf_nan
);
276 ATF_TP_ADD_TC(tp
, tanf_inf_neg
);
277 ATF_TP_ADD_TC(tp
, tanf_inf_pos
);
278 ATF_TP_ADD_TC(tp
, tanf_zero_neg
);
279 ATF_TP_ADD_TC(tp
, tanf_zero_pos
);
281 return atf_no_error();