1 /* $NetBSD: t_asin.c,v 1.2 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.9, -1.119769514998634, },
42 { -0.1, -0.1001674211615598, },
43 { 0.1, 0.1001674211615598, },
45 { 0.9, 1.119769514998634, },
53 ATF_TC_HEAD(asin_nan
, tc
)
55 atf_tc_set_md_var(tc
, "descr", "Test asin(NaN) == NaN");
58 ATF_TC_BODY(asin_nan
, tc
)
61 const double x
= 0.0L / 0.0L;
63 if (isnan(asin(x
)) == 0)
64 atf_tc_fail_nonfatal("asin(NaN) != NaN");
69 ATF_TC_HEAD(asin_inf_neg
, tc
)
71 atf_tc_set_md_var(tc
, "descr", "Test asin(-Inf) == NaN");
74 ATF_TC_BODY(asin_inf_neg
, tc
)
77 const double x
= -1.0L / 0.0L;
79 if (isnan(asin(x
)) == 0)
80 atf_tc_fail_nonfatal("asin(-Inf) != NaN");
85 ATF_TC_HEAD(asin_inf_pos
, tc
)
87 atf_tc_set_md_var(tc
, "descr", "Test asin(+Inf) == NaN");
90 ATF_TC_BODY(asin_inf_pos
, tc
)
93 const double x
= 1.0L / 0.0L;
95 if (isnan(asin(x
)) == 0)
96 atf_tc_fail_nonfatal("asin(+Inf) != NaN");
101 ATF_TC_HEAD(asin_range
, tc
)
103 atf_tc_set_md_var(tc
, "descr", "Test asin(x) == NaN, x < -1, x > 1");
106 ATF_TC_BODY(asin_range
, tc
)
109 const double x
[] = { -1.1, -1.000000001, 1.1, 1.000000001 };
112 for (i
= 0; i
< __arraycount(x
); i
++) {
114 if (isnan(asin(x
[i
])) == 0)
115 atf_tc_fail_nonfatal("asin(%f) != NaN", x
[i
]);
120 ATF_TC(asin_inrange
);
121 ATF_TC_HEAD(asin_inrange
, tc
)
123 atf_tc_set_md_var(tc
, "descr", "Test asin(x) for some values");
126 ATF_TC_BODY(asin_inrange
, tc
)
129 const double eps
= 1.0e-15;
133 for (i
= 0; i
< __arraycount(values
); i
++) {
134 y
= asin(values
[i
].x
);
135 if (fabs(y
- values
[i
].y
) > eps
)
136 atf_tc_fail_nonfatal("asin(%g) != %g",
137 values
[i
].x
, values
[i
].y
);
142 ATF_TC(asin_zero_neg
);
143 ATF_TC_HEAD(asin_zero_neg
, tc
)
145 atf_tc_set_md_var(tc
, "descr", "Test asin(-0.0) == -0.0");
148 ATF_TC_BODY(asin_zero_neg
, tc
)
151 const double x
= -0.0L;
154 if (fabs(y
) > 0.0 || signbit(y
) == 0)
155 atf_tc_fail_nonfatal("asin(-0.0) != -0.0");
159 ATF_TC(asin_zero_pos
);
160 ATF_TC_HEAD(asin_zero_pos
, tc
)
162 atf_tc_set_md_var(tc
, "descr", "Test asin(+0.0) == +0.0");
165 ATF_TC_BODY(asin_zero_pos
, tc
)
168 const double x
= 0.0L;
171 if (fabs(y
) > 0.0 || signbit(y
) != 0)
172 atf_tc_fail_nonfatal("asin(+0.0) != +0.0");
180 ATF_TC_HEAD(asinf_nan
, tc
)
182 atf_tc_set_md_var(tc
, "descr", "Test asinf(NaN) == NaN");
185 ATF_TC_BODY(asinf_nan
, tc
)
188 const float x
= 0.0L / 0.0L;
190 if (isnan(asinf(x
)) == 0)
191 atf_tc_fail_nonfatal("asinf(NaN) != NaN");
195 ATF_TC(asinf_inf_neg
);
196 ATF_TC_HEAD(asinf_inf_neg
, tc
)
198 atf_tc_set_md_var(tc
, "descr", "Test asinf(-Inf) == NaN");
201 ATF_TC_BODY(asinf_inf_neg
, tc
)
204 const float x
= -1.0L / 0.0L;
206 if (isnan(asinf(x
)) == 0)
207 atf_tc_fail_nonfatal("asinf(-Inf) != NaN");
211 ATF_TC(asinf_inf_pos
);
212 ATF_TC_HEAD(asinf_inf_pos
, tc
)
214 atf_tc_set_md_var(tc
, "descr", "Test asinf(+Inf) == NaN");
217 ATF_TC_BODY(asinf_inf_pos
, tc
)
220 const float x
= 1.0L / 0.0L;
222 if (isnan(asinf(x
)) == 0)
223 atf_tc_fail_nonfatal("asinf(+Inf) != NaN");
228 ATF_TC_HEAD(asinf_range
, tc
)
230 atf_tc_set_md_var(tc
, "descr", "Test asinf(x) == NaN, x < -1, x > 1");
233 ATF_TC_BODY(asinf_range
, tc
)
236 const float x
[] = { -1.1, -1.0000001, 1.1, 1.0000001 };
239 for (i
= 0; i
< __arraycount(x
); i
++) {
241 if (isnan(asinf(x
[i
])) == 0)
242 atf_tc_fail_nonfatal("asinf(%f) != NaN", x
[i
]);
247 ATF_TC(asinf_inrange
);
248 ATF_TC_HEAD(asinf_inrange
, tc
)
250 atf_tc_set_md_var(tc
, "descr", "Test asinf(x) for some values");
253 ATF_TC_BODY(asinf_inrange
, tc
)
256 const float eps
= 1.0e-6;
261 for (i
= 0; i
< __arraycount(values
); i
++) {
264 if (fabs(asinf(x
) - y
) > eps
)
265 atf_tc_fail_nonfatal("asinf(%g) != %g", x
, y
);
270 ATF_TC(asinf_zero_neg
);
271 ATF_TC_HEAD(asinf_zero_neg
, tc
)
273 atf_tc_set_md_var(tc
, "descr", "Test asinf(-0.0) == -0.0");
276 ATF_TC_BODY(asinf_zero_neg
, tc
)
279 const float x
= -0.0L;
282 if (fabsf(y
) > 0.0 || signbit(y
) == 0)
283 atf_tc_fail_nonfatal("asinf(-0.0) != -0.0");
287 ATF_TC(asinf_zero_pos
);
288 ATF_TC_HEAD(asinf_zero_pos
, tc
)
290 atf_tc_set_md_var(tc
, "descr", "Test asinf(+0.0) == +0.0");
293 ATF_TC_BODY(asinf_zero_pos
, tc
)
296 const float x
= 0.0L;
299 if (fabsf(y
) > 0.0 || signbit(y
) != 0)
300 atf_tc_fail_nonfatal("asinf(+0.0) != +0.0");
307 ATF_TP_ADD_TC(tp
, asin_nan
);
308 ATF_TP_ADD_TC(tp
, asin_inf_neg
);
309 ATF_TP_ADD_TC(tp
, asin_inf_pos
);
310 ATF_TP_ADD_TC(tp
, asin_range
);
311 ATF_TP_ADD_TC(tp
, asin_inrange
);
312 ATF_TP_ADD_TC(tp
, asin_zero_neg
);
313 ATF_TP_ADD_TC(tp
, asin_zero_pos
);
315 ATF_TP_ADD_TC(tp
, asinf_nan
);
316 ATF_TP_ADD_TC(tp
, asinf_inf_neg
);
317 ATF_TP_ADD_TC(tp
, asinf_inf_pos
);
318 ATF_TP_ADD_TC(tp
, asinf_range
);
319 ATF_TP_ADD_TC(tp
, asinf_inrange
);
320 ATF_TP_ADD_TC(tp
, asinf_zero_neg
);
321 ATF_TP_ADD_TC(tp
, asinf_zero_pos
);
323 return atf_no_error();