tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libm / t_atan.c
blobca8cd701c219686b06df98f67e97017e394c7915
1 /* $NetBSD: t_atan.c,v 1.9 2013/06/14 05:39:28 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 { -100, -1.560796660108231, },
40 { -10, -1.471127674303735, },
41 { -1, -M_PI / 4, },
42 { -0.1, -0.09966865249116204, },
43 { 0.1, 0.09966865249116204, },
44 { 1, M_PI / 4, },
45 { 10, 1.471127674303735, },
46 { 100, 1.560796660108231, },
50 * atan(3)
52 ATF_TC(atan_nan);
53 ATF_TC_HEAD(atan_nan, tc)
55 atf_tc_set_md_var(tc, "descr", "Test atan(NaN) == NaN");
58 ATF_TC_BODY(atan_nan, tc)
60 #ifndef __vax__
61 const double x = 0.0L / 0.0L;
63 if (isnan(atan(x)) == 0)
64 atf_tc_fail_nonfatal("atan(NaN) != NaN");
65 #endif
68 ATF_TC(atan_inf_neg);
69 ATF_TC_HEAD(atan_inf_neg, tc)
71 atf_tc_set_md_var(tc, "descr", "Test atan(-Inf) == -pi/2");
74 ATF_TC_BODY(atan_inf_neg, tc)
76 #ifndef __vax__
77 const double x = -1.0L / 0.0L;
78 const double eps = 1.0e-15;
80 if (fabs(atan(x) + M_PI_2) > eps)
81 atf_tc_fail_nonfatal("atan(-Inf) != -pi/2");
82 #endif
85 ATF_TC(atan_inf_pos);
86 ATF_TC_HEAD(atan_inf_pos, tc)
88 atf_tc_set_md_var(tc, "descr", "Test atan(+Inf) == pi/2");
91 ATF_TC_BODY(atan_inf_pos, tc)
93 #ifndef __vax__
94 const double x = +1.0L / 0.0L;
95 const double eps = 1.0e-15;
97 if (fabs(atan(x) - M_PI_2) > eps)
98 atf_tc_fail_nonfatal("atan(+Inf) != pi/2");
99 #endif
102 ATF_TC(atan_inrange);
103 ATF_TC_HEAD(atan_inrange, tc)
105 atf_tc_set_md_var(tc, "descr", "Test atan(x) for some values");
108 ATF_TC_BODY(atan_inrange, tc)
110 #ifndef __vax__
111 const double eps = 1.0e-15;
112 size_t i;
114 for (i = 0; i < __arraycount(values); i++) {
115 if (fabs(atan(values[i].x) - values[i].y) > eps)
116 atf_tc_fail_nonfatal("atan(%g) != %g",
117 values[i].x, values[i].y);
119 #endif
122 ATF_TC(atan_zero_neg);
123 ATF_TC_HEAD(atan_zero_neg, tc)
125 atf_tc_set_md_var(tc, "descr", "Test atan(-0.0) == -0.0");
128 ATF_TC_BODY(atan_zero_neg, tc)
130 #ifndef __vax__
131 const double x = -0.0L;
132 double y = atan(x);
134 if (fabs(y) > 0.0 || signbit(y) == 0)
135 atf_tc_fail_nonfatal("atan(-0.0) != -0.0");
136 #endif
139 ATF_TC(atan_zero_pos);
140 ATF_TC_HEAD(atan_zero_pos, tc)
142 atf_tc_set_md_var(tc, "descr", "Test atan(+0.0) == +0.0");
145 ATF_TC_BODY(atan_zero_pos, tc)
147 #ifndef __vax__
148 const double x = 0.0L;
149 double y = atan(x);
151 if (fabs(y) > 0.0 || signbit(y) != 0)
152 atf_tc_fail_nonfatal("atan(+0.0) != +0.0");
153 #endif
157 * atanf(3)
159 ATF_TC(atanf_nan);
160 ATF_TC_HEAD(atanf_nan, tc)
162 atf_tc_set_md_var(tc, "descr", "Test atanf(NaN) == NaN");
165 ATF_TC_BODY(atanf_nan, tc)
167 #ifndef __vax__
168 const float x = 0.0L / 0.0L;
170 if (isnan(atanf(x)) == 0)
171 atf_tc_fail_nonfatal("atanf(NaN) != NaN");
172 #endif
175 ATF_TC(atanf_inf_neg);
176 ATF_TC_HEAD(atanf_inf_neg, tc)
178 atf_tc_set_md_var(tc, "descr", "Test atanf(-Inf) == -pi/2");
181 ATF_TC_BODY(atanf_inf_neg, tc)
183 #ifndef __vax__
184 const float x = -1.0L / 0.0L;
185 const float eps = 1.0e-7;
187 if (fabsf(atanf(x) + M_PI_2) > eps)
188 atf_tc_fail_nonfatal("atanf(-Inf) != -pi/2");
189 #endif
192 ATF_TC(atanf_inf_pos);
193 ATF_TC_HEAD(atanf_inf_pos, tc)
195 atf_tc_set_md_var(tc, "descr", "Test atanf(+Inf) == pi/2");
198 ATF_TC_BODY(atanf_inf_pos, tc)
200 #ifndef __vax__
201 const float x = +1.0L / 0.0L;
202 const float eps = 1.0e-7;
204 if (fabsf(atanf(x) - M_PI_2) > eps)
205 atf_tc_fail_nonfatal("atanf(+Inf) != pi/2");
206 #endif
209 ATF_TC(atanf_inrange);
210 ATF_TC_HEAD(atanf_inrange, tc)
212 atf_tc_set_md_var(tc, "descr", "Test atanf(x) for some values");
215 ATF_TC_BODY(atanf_inrange, tc)
217 #ifndef __vax__
218 const float eps = 1.0e-7;
219 float x;
220 float y;
221 size_t i;
223 for (i = 0; i < __arraycount(values); i++) {
224 x = values[i].x;
225 y = values[i].y;
226 if (fabs(atanf(x) - y) > eps)
227 atf_tc_fail_nonfatal("atan(%g) != %g", x, y);
229 #endif
232 ATF_TC(atanf_zero_neg);
233 ATF_TC_HEAD(atanf_zero_neg, tc)
235 atf_tc_set_md_var(tc, "descr", "Test atanf(-0.0) == -0.0");
238 ATF_TC_BODY(atanf_zero_neg, tc)
240 #ifndef __vax__
241 const float x = -0.0L;
242 float y = atanf(x);
244 if (fabsf(y) > 0.0 || signbit(y) == 0)
245 atf_tc_fail_nonfatal("atanf(-0.0) != -0.0");
246 #endif
249 ATF_TC(atanf_zero_pos);
250 ATF_TC_HEAD(atanf_zero_pos, tc)
252 atf_tc_set_md_var(tc, "descr", "Test atanf(+0.0) == +0.0");
255 ATF_TC_BODY(atanf_zero_pos, tc)
257 #ifndef __vax__
258 const float x = 0.0L;
259 float y = atanf(x);
261 if (fabsf(y) > 0.0 || signbit(y) != 0)
262 atf_tc_fail_nonfatal("atanf(+0.0) != +0.0");
263 #endif
266 ATF_TP_ADD_TCS(tp)
269 ATF_TP_ADD_TC(tp, atan_nan);
270 ATF_TP_ADD_TC(tp, atan_inf_neg);
271 ATF_TP_ADD_TC(tp, atan_inf_pos);
272 ATF_TP_ADD_TC(tp, atan_inrange);
273 ATF_TP_ADD_TC(tp, atan_zero_neg);
274 ATF_TP_ADD_TC(tp, atan_zero_pos);
276 ATF_TP_ADD_TC(tp, atanf_nan);
277 ATF_TP_ADD_TC(tp, atanf_inf_neg);
278 ATF_TP_ADD_TC(tp, atanf_inf_pos);
279 ATF_TP_ADD_TC(tp, atanf_inrange);
280 ATF_TP_ADD_TC(tp, atanf_zero_neg);
281 ATF_TP_ADD_TC(tp, atanf_zero_pos);
283 return atf_no_error();