tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libm / t_acos.c
blob03f169ff177e8544cf05adac7fd9b93bbf98818c
1 /* $NetBSD: t_acos.c,v 1.4 2013/04/09 12:11:04 isaki 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 double x;
37 double y;
38 } values[] = {
39 { -1, M_PI, },
40 { -0.99, 3.000053180265366, },
41 { -0.5, 2.094395102393195, },
42 { -0.1, 1.670963747956456, },
43 { 0, M_PI / 2, },
44 { 0.1, 1.470628905633337, },
45 { 0.5, 1.047197551196598, },
46 { 0.99, 0.141539473324427, },
50 * acos(3)
52 ATF_TC(acos_nan);
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)
60 #ifndef __vax__
61 const double x = 0.0L / 0.0L;
63 if (isnan(acos(x)) == 0)
64 atf_tc_fail_nonfatal("acos(NaN) != NaN");
65 #endif
68 ATF_TC(acos_inf_neg);
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)
76 #ifndef __vax__
77 const double x = -1.0L / 0.0L;
79 if (isnan(acos(x)) == 0)
80 atf_tc_fail_nonfatal("acos(-Inf) != NaN");
81 #endif
84 ATF_TC(acos_inf_pos);
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)
92 #ifndef __vax__
93 const double x = 1.0L / 0.0L;
95 if (isnan(acos(x)) == 0)
96 atf_tc_fail_nonfatal("acos(+Inf) != NaN");
97 #endif
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)
108 #ifndef __vax__
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");
113 #endif
116 ATF_TC(acos_range);
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)
124 #ifndef __vax__
125 const double x[] = { -1.1, -1.000000001, 1.1, 1.000000001 };
126 size_t i;
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]);
133 #endif
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)
144 #ifndef __vax__
145 const double eps = 1.0e-15;
146 double x;
147 double y;
148 size_t i;
150 for (i = 0; i < __arraycount(values); i++) {
151 x = values[i].x;
152 y = values[i].y;
153 if (fabs(acos(x) - y) > eps)
154 atf_tc_fail_nonfatal("acos(%g) != %g", x, y);
156 #endif
160 * acosf(3)
162 ATF_TC(acosf_nan);
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)
170 #ifndef __vax__
171 const float x = 0.0L / 0.0L;
173 if (isnan(acosf(x)) == 0)
174 atf_tc_fail_nonfatal("acosf(NaN) != NaN");
175 #endif
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)
186 #ifndef __vax__
187 const float x = -1.0L / 0.0L;
189 if (isnan(acosf(x)) == 0)
190 atf_tc_fail_nonfatal("acosf(-Inf) != NaN");
191 #endif
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)
202 #ifndef __vax__
203 const float x = 1.0L / 0.0L;
205 if (isnan(acosf(x)) == 0)
206 atf_tc_fail_nonfatal("acosf(+Inf) != NaN");
207 #endif
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)
218 #ifndef __vax__
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");
223 #endif
226 ATF_TC(acosf_range);
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)
234 #ifndef __vax__
235 const float x[] = { -1.1, -1.0000001, 1.1, 1.0000001 };
236 size_t i;
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]);
243 #endif
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)
254 #ifndef __vax__
255 const float eps = 1.0e-5;
256 float x;
257 float y;
258 size_t i;
260 for (i = 0; i < __arraycount(values); i++) {
261 x = values[i].x;
262 y = values[i].y;
263 if (fabsf(acosf(x) - y) > eps)
264 atf_tc_fail_nonfatal("acosf(%g) != %g", x, y);
266 #endif
269 ATF_TP_ADD_TCS(tp)
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();