1 /* $NetBSD: t_sin.c,v 1.3 2011/09/14 13:29:58 jruoho 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, -0.7071067811865476 },
42 { -90, -1.570796326794897, -1.0000000000000000 },
43 { -45, -0.785398163397448, -0.7071067811865476 },
44 { 0, 0.000000000000000, 0.0000000000000000 },
45 { 30, 0.523598775598299, 0.5000000000000000 },
46 { 45, 0.785398163397448, 0.7071067811865476 },
47 { 60, 1.047197551196598, 0.8660254037844386 },
48 { 90, 1.570796326794897, 1.0000000000000000 },
49 { 120, 2.094395102393195, 0.8660254037844386 },
50 { 135, 2.356194490192345, 0.7071067811865476 },
51 { 150, 2.617993877991494, 0.5000000000000000 },
52 { 180, 3.141592653589793, 0.0000000000000000 },
53 { 270, 4.712388980384690, -1.0000000000000000 },
54 { 360, 6.283185307179586, 0.0000000000000000 }
61 ATF_TC_HEAD(sin_angles
, tc
)
63 atf_tc_set_md_var(tc
, "descr", "Test some selected angles");
66 ATF_TC_BODY(sin_angles
, tc
)
68 const double eps
= 1.0e-15;
71 for (i
= 0; i
< __arraycount(angles
); i
++) {
73 if (fabs(sin(angles
[i
].x
) - angles
[i
].y
) > eps
)
74 atf_tc_fail_nonfatal("sin(%d deg) != %0.01f",
75 angles
[i
].angle
, angles
[i
].y
);
80 ATF_TC_HEAD(sin_nan
, tc
)
82 atf_tc_set_md_var(tc
, "descr", "Test sin(NaN) == NaN");
85 ATF_TC_BODY(sin_nan
, tc
)
88 const double x
= 0.0L / 0.0L;
90 ATF_CHECK(isnan(x
) != 0);
91 ATF_CHECK(isnan(sin(x
)) != 0);
96 ATF_TC_HEAD(sin_inf_neg
, tc
)
98 atf_tc_set_md_var(tc
, "descr", "Test sin(-Inf) == NaN");
101 ATF_TC_BODY(sin_inf_neg
, tc
)
104 const double x
= -1.0L / 0.0L;
106 ATF_CHECK(isnan(sin(x
)) != 0);
111 ATF_TC_HEAD(sin_inf_pos
, tc
)
113 atf_tc_set_md_var(tc
, "descr", "Test sin(+Inf) == NaN");
116 ATF_TC_BODY(sin_inf_pos
, tc
)
119 const double x
= 1.0L / 0.0L;
121 ATF_CHECK(isnan(sin(x
)) != 0);
126 ATF_TC(sin_zero_neg
);
127 ATF_TC_HEAD(sin_zero_neg
, tc
)
129 atf_tc_set_md_var(tc
, "descr", "Test sin(-0.0) == -0.0");
132 ATF_TC_BODY(sin_zero_neg
, tc
)
135 const double x
= -0.0L;
137 ATF_CHECK(sin(x
) == x
);
141 ATF_TC(sin_zero_pos
);
142 ATF_TC_HEAD(sin_zero_pos
, tc
)
144 atf_tc_set_md_var(tc
, "descr", "Test sin(+0.0) == +0.0");
147 ATF_TC_BODY(sin_zero_pos
, tc
)
150 const double x
= 0.0L;
152 ATF_CHECK(sin(x
) == x
);
160 ATF_TC_HEAD(sinf_angles
, tc
)
162 atf_tc_set_md_var(tc
, "descr", "Test some selected angles");
165 ATF_TC_BODY(sinf_angles
, tc
)
167 const float eps
= 1.0e-6;
171 for (i
= 0; i
< __arraycount(angles
); i
++) {
176 if (fabsf(sinf(x
) - y
) > eps
)
177 atf_tc_fail_nonfatal("sinf(%d deg) != %0.01f",
178 angles
[i
].angle
, angles
[i
].y
);
183 ATF_TC_HEAD(sinf_nan
, tc
)
185 atf_tc_set_md_var(tc
, "descr", "Test sinf(NaN) == NaN");
188 ATF_TC_BODY(sinf_nan
, tc
)
191 const float x
= 0.0L / 0.0L;
193 ATF_CHECK(isnan(x
) != 0);
194 ATF_CHECK(isnan(sinf(x
)) != 0);
198 ATF_TC(sinf_inf_neg
);
199 ATF_TC_HEAD(sinf_inf_neg
, tc
)
201 atf_tc_set_md_var(tc
, "descr", "Test sinf(-Inf) == NaN");
204 ATF_TC_BODY(sinf_inf_neg
, tc
)
207 const float x
= -1.0L / 0.0L;
209 if (isnan(sinf(x
)) == 0) {
210 atf_tc_expect_fail("PR lib/45362");
211 atf_tc_fail("sinf(-Inf) != NaN");
216 ATF_TC(sinf_inf_pos
);
217 ATF_TC_HEAD(sinf_inf_pos
, tc
)
219 atf_tc_set_md_var(tc
, "descr", "Test sinf(+Inf) == NaN");
222 ATF_TC_BODY(sinf_inf_pos
, tc
)
225 const float x
= 1.0L / 0.0L;
227 if (isnan(sinf(x
)) == 0) {
228 atf_tc_expect_fail("PR lib/45362");
229 atf_tc_fail("sinf(+Inf) != NaN");
235 ATF_TC(sinf_zero_neg
);
236 ATF_TC_HEAD(sinf_zero_neg
, tc
)
238 atf_tc_set_md_var(tc
, "descr", "Test sinf(-0.0) == -0.0");
241 ATF_TC_BODY(sinf_zero_neg
, tc
)
244 const float x
= -0.0L;
246 ATF_CHECK(sinf(x
) == x
);
250 ATF_TC(sinf_zero_pos
);
251 ATF_TC_HEAD(sinf_zero_pos
, tc
)
253 atf_tc_set_md_var(tc
, "descr", "Test sinf(+0.0) == +0.0");
256 ATF_TC_BODY(sinf_zero_pos
, tc
)
259 const float x
= 0.0L;
261 ATF_CHECK(sinf(x
) == x
);
268 ATF_TP_ADD_TC(tp
, sin_angles
);
269 ATF_TP_ADD_TC(tp
, sin_nan
);
270 ATF_TP_ADD_TC(tp
, sin_inf_neg
);
271 ATF_TP_ADD_TC(tp
, sin_inf_pos
);
272 ATF_TP_ADD_TC(tp
, sin_zero_neg
);
273 ATF_TP_ADD_TC(tp
, sin_zero_pos
);
275 ATF_TP_ADD_TC(tp
, sinf_angles
);
276 ATF_TP_ADD_TC(tp
, sinf_nan
);
277 ATF_TP_ADD_TC(tp
, sinf_inf_neg
);
278 ATF_TP_ADD_TC(tp
, sinf_inf_pos
);
279 ATF_TP_ADD_TC(tp
, sinf_zero_neg
);
280 ATF_TP_ADD_TC(tp
, sinf_zero_pos
);
282 return atf_no_error();