1 /* $NetBSD: t_atan.c,v 1.9 2013/06/14 05:39:28 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.
39 { -100, -1.560796660108231, },
40 { -10, -1.471127674303735, },
42 { -0.1, -0.09966865249116204, },
43 { 0.1, 0.09966865249116204, },
45 { 10, 1.471127674303735, },
46 { 100, 1.560796660108231, },
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
)
61 const double x
= 0.0L / 0.0L;
63 if (isnan(atan(x
)) == 0)
64 atf_tc_fail_nonfatal("atan(NaN) != NaN");
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
)
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");
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
)
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");
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
)
111 const double eps
= 1.0e-15;
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
);
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
)
131 const double x
= -0.0L;
134 if (fabs(y
) > 0.0 || signbit(y
) == 0)
135 atf_tc_fail_nonfatal("atan(-0.0) != -0.0");
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
)
148 const double x
= 0.0L;
151 if (fabs(y
) > 0.0 || signbit(y
) != 0)
152 atf_tc_fail_nonfatal("atan(+0.0) != +0.0");
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
)
168 const float x
= 0.0L / 0.0L;
170 if (isnan(atanf(x
)) == 0)
171 atf_tc_fail_nonfatal("atanf(NaN) != NaN");
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
)
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");
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
)
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");
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
)
218 const float eps
= 1.0e-7;
223 for (i
= 0; i
< __arraycount(values
); i
++) {
226 if (fabs(atanf(x
) - y
) > eps
)
227 atf_tc_fail_nonfatal("atan(%g) != %g", x
, y
);
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
)
241 const float x
= -0.0L;
244 if (fabsf(y
) > 0.0 || signbit(y
) == 0)
245 atf_tc_fail_nonfatal("atanf(-0.0) != -0.0");
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
)
258 const float x
= 0.0L;
261 if (fabsf(y
) > 0.0 || signbit(y
) != 0)
262 atf_tc_fail_nonfatal("atanf(+0.0) != +0.0");
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();