1 /* $NetBSD: t_acos.c,v 1.4 2013/04/09 12:11:04 isaki 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 { -0.99, 3.000053180265366, },
41 { -0.5, 2.094395102393195, },
42 { -0.1, 1.670963747956456, },
44 { 0.1, 1.470628905633337, },
45 { 0.5, 1.047197551196598, },
46 { 0.99, 0.141539473324427, },
53 ATF_TC_HEAD(acos_nan
, tc
)
55 atf_tc_set_md_var(tc
, "descr", "Test acos(NaN) == NaN");
58 ATF_TC_BODY(acos_nan
, tc
)
61 const double x
= 0.0L / 0.0L;
63 if (isnan(acos(x
)) == 0)
64 atf_tc_fail_nonfatal("acos(NaN) != NaN");
69 ATF_TC_HEAD(acos_inf_neg
, tc
)
71 atf_tc_set_md_var(tc
, "descr", "Test acos(-Inf) == NaN");
74 ATF_TC_BODY(acos_inf_neg
, tc
)
77 const double x
= -1.0L / 0.0L;
79 if (isnan(acos(x
)) == 0)
80 atf_tc_fail_nonfatal("acos(-Inf) != NaN");
85 ATF_TC_HEAD(acos_inf_pos
, tc
)
87 atf_tc_set_md_var(tc
, "descr", "Test acos(+Inf) == NaN");
90 ATF_TC_BODY(acos_inf_pos
, tc
)
93 const double x
= 1.0L / 0.0L;
95 if (isnan(acos(x
)) == 0)
96 atf_tc_fail_nonfatal("acos(+Inf) != NaN");
100 ATF_TC(acos_one_pos
);
101 ATF_TC_HEAD(acos_one_pos
, tc
)
103 atf_tc_set_md_var(tc
, "descr", "Test acos(1.0) == +0.0");
106 ATF_TC_BODY(acos_one_pos
, tc
)
109 const double y
= acos(1.0);
111 if (fabs(y
) > 0.0 || signbit(y
) != 0)
112 atf_tc_fail_nonfatal("acos(1.0) != +0.0");
117 ATF_TC_HEAD(acos_range
, tc
)
119 atf_tc_set_md_var(tc
, "descr", "Test acos(x) == NaN, x < -1, x > 1");
122 ATF_TC_BODY(acos_range
, tc
)
125 const double x
[] = { -1.1, -1.000000001, 1.1, 1.000000001 };
128 for (i
= 0; i
< __arraycount(x
); i
++) {
130 if (isnan(acos(x
[i
])) == 0)
131 atf_tc_fail_nonfatal("acos(%f) != NaN", x
[i
]);
136 ATF_TC(acos_inrange
);
137 ATF_TC_HEAD(acos_inrange
, tc
)
139 atf_tc_set_md_var(tc
, "descr", "Test acos(x) for some values");
142 ATF_TC_BODY(acos_inrange
, tc
)
145 const double eps
= 1.0e-15;
150 for (i
= 0; i
< __arraycount(values
); i
++) {
153 if (fabs(acos(x
) - y
) > eps
)
154 atf_tc_fail_nonfatal("acos(%g) != %g", x
, y
);
163 ATF_TC_HEAD(acosf_nan
, tc
)
165 atf_tc_set_md_var(tc
, "descr", "Test acosf(NaN) == NaN");
168 ATF_TC_BODY(acosf_nan
, tc
)
171 const float x
= 0.0L / 0.0L;
173 if (isnan(acosf(x
)) == 0)
174 atf_tc_fail_nonfatal("acosf(NaN) != NaN");
178 ATF_TC(acosf_inf_neg
);
179 ATF_TC_HEAD(acosf_inf_neg
, tc
)
181 atf_tc_set_md_var(tc
, "descr", "Test acosf(-Inf) == NaN");
184 ATF_TC_BODY(acosf_inf_neg
, tc
)
187 const float x
= -1.0L / 0.0L;
189 if (isnan(acosf(x
)) == 0)
190 atf_tc_fail_nonfatal("acosf(-Inf) != NaN");
194 ATF_TC(acosf_inf_pos
);
195 ATF_TC_HEAD(acosf_inf_pos
, tc
)
197 atf_tc_set_md_var(tc
, "descr", "Test acosf(+Inf) == NaN");
200 ATF_TC_BODY(acosf_inf_pos
, tc
)
203 const float x
= 1.0L / 0.0L;
205 if (isnan(acosf(x
)) == 0)
206 atf_tc_fail_nonfatal("acosf(+Inf) != NaN");
210 ATF_TC(acosf_one_pos
);
211 ATF_TC_HEAD(acosf_one_pos
, tc
)
213 atf_tc_set_md_var(tc
, "descr", "Test acosf(1.0) == +0.0");
216 ATF_TC_BODY(acosf_one_pos
, tc
)
219 const float y
= acosf(1.0);
221 if (fabsf(y
) > 0.0 || signbit(y
) != 0)
222 atf_tc_fail_nonfatal("acosf(1.0) != +0.0");
227 ATF_TC_HEAD(acosf_range
, tc
)
229 atf_tc_set_md_var(tc
, "descr", "Test acosf(x) == NaN, x < -1, x > 1");
232 ATF_TC_BODY(acosf_range
, tc
)
235 const float x
[] = { -1.1, -1.0000001, 1.1, 1.0000001 };
238 for (i
= 0; i
< __arraycount(x
); i
++) {
240 if (isnan(acosf(x
[i
])) == 0)
241 atf_tc_fail_nonfatal("acosf(%f) != NaN", x
[i
]);
246 ATF_TC(acosf_inrange
);
247 ATF_TC_HEAD(acosf_inrange
, tc
)
249 atf_tc_set_md_var(tc
, "descr", "Test acosf(x) for some values");
252 ATF_TC_BODY(acosf_inrange
, tc
)
255 const float eps
= 1.0e-5;
260 for (i
= 0; i
< __arraycount(values
); i
++) {
263 if (fabsf(acosf(x
) - y
) > eps
)
264 atf_tc_fail_nonfatal("acosf(%g) != %g", x
, y
);
272 ATF_TP_ADD_TC(tp
, acos_nan
);
273 ATF_TP_ADD_TC(tp
, acos_inf_neg
);
274 ATF_TP_ADD_TC(tp
, acos_inf_pos
);
275 ATF_TP_ADD_TC(tp
, acos_one_pos
);
276 ATF_TP_ADD_TC(tp
, acos_range
);
277 ATF_TP_ADD_TC(tp
, acos_inrange
);
279 ATF_TP_ADD_TC(tp
, acosf_nan
);
280 ATF_TP_ADD_TC(tp
, acosf_inf_neg
);
281 ATF_TP_ADD_TC(tp
, acosf_inf_pos
);
282 ATF_TP_ADD_TC(tp
, acosf_one_pos
);
283 ATF_TP_ADD_TC(tp
, acosf_range
);
284 ATF_TP_ADD_TC(tp
, acosf_inrange
);
286 return atf_no_error();