Remove building with NOCRYPTO option
[minix3.git] / tests / lib / libm / t_asin.c
blob06de85216429ea9ece82c12ad6d837b67d9fca39
1 /* $NetBSD: t_asin.c,v 1.3 2014/03/03 10:39:08 martin 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.0, -M_PI / 2, },
40 { -0.9, -1.119769514998634, },
41 { -0.5, -M_PI / 6, },
42 { -0.1, -0.1001674211615598, },
43 { 0.1, 0.1001674211615598, },
44 { 0.5, M_PI / 6, },
45 { 0.9, 1.119769514998634, },
46 { 1.0, M_PI / 2, },
50 * asin(3)
52 ATF_TC(asin_nan);
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)
60 const double x = 0.0L / 0.0L;
62 if (isnan(asin(x)) == 0)
63 atf_tc_fail_nonfatal("asin(NaN) != NaN");
66 ATF_TC(asin_inf_neg);
67 ATF_TC_HEAD(asin_inf_neg, tc)
69 atf_tc_set_md_var(tc, "descr", "Test asin(-Inf) == NaN");
72 ATF_TC_BODY(asin_inf_neg, tc)
74 const double x = -1.0L / 0.0L;
76 if (isnan(asin(x)) == 0)
77 atf_tc_fail_nonfatal("asin(-Inf) != NaN");
80 ATF_TC(asin_inf_pos);
81 ATF_TC_HEAD(asin_inf_pos, tc)
83 atf_tc_set_md_var(tc, "descr", "Test asin(+Inf) == NaN");
86 ATF_TC_BODY(asin_inf_pos, tc)
88 const double x = 1.0L / 0.0L;
90 if (isnan(asin(x)) == 0)
91 atf_tc_fail_nonfatal("asin(+Inf) != NaN");
94 ATF_TC(asin_range);
95 ATF_TC_HEAD(asin_range, tc)
97 atf_tc_set_md_var(tc, "descr", "Test asin(x) == NaN, x < -1, x > 1");
100 ATF_TC_BODY(asin_range, tc)
102 const double x[] = { -1.1, -1.000000001, 1.1, 1.000000001 };
103 size_t i;
105 for (i = 0; i < __arraycount(x); i++) {
107 if (isnan(asin(x[i])) == 0)
108 atf_tc_fail_nonfatal("asin(%f) != NaN", x[i]);
112 ATF_TC(asin_inrange);
113 ATF_TC_HEAD(asin_inrange, tc)
115 atf_tc_set_md_var(tc, "descr", "Test asin(x) for some values");
118 ATF_TC_BODY(asin_inrange, tc)
120 const double eps = 1.0e-15;
121 double y;
122 size_t i;
124 for (i = 0; i < __arraycount(values); i++) {
125 y = asin(values[i].x);
126 if (fabs(y - values[i].y) > eps)
127 atf_tc_fail_nonfatal("asin(%g) != %g",
128 values[i].x, values[i].y);
132 ATF_TC(asin_zero_neg);
133 ATF_TC_HEAD(asin_zero_neg, tc)
135 atf_tc_set_md_var(tc, "descr", "Test asin(-0.0) == -0.0");
138 ATF_TC_BODY(asin_zero_neg, tc)
140 const double x = -0.0L;
141 double y = asin(x);
143 if (fabs(y) > 0.0 || signbit(y) == 0)
144 atf_tc_fail_nonfatal("asin(-0.0) != -0.0");
147 ATF_TC(asin_zero_pos);
148 ATF_TC_HEAD(asin_zero_pos, tc)
150 atf_tc_set_md_var(tc, "descr", "Test asin(+0.0) == +0.0");
153 ATF_TC_BODY(asin_zero_pos, tc)
155 const double x = 0.0L;
156 double y = asin(x);
158 if (fabs(y) > 0.0 || signbit(y) != 0)
159 atf_tc_fail_nonfatal("asin(+0.0) != +0.0");
163 * asinf(3)
165 ATF_TC(asinf_nan);
166 ATF_TC_HEAD(asinf_nan, tc)
168 atf_tc_set_md_var(tc, "descr", "Test asinf(NaN) == NaN");
171 ATF_TC_BODY(asinf_nan, tc)
173 const float x = 0.0L / 0.0L;
175 if (isnan(asinf(x)) == 0)
176 atf_tc_fail_nonfatal("asinf(NaN) != NaN");
179 ATF_TC(asinf_inf_neg);
180 ATF_TC_HEAD(asinf_inf_neg, tc)
182 atf_tc_set_md_var(tc, "descr", "Test asinf(-Inf) == NaN");
185 ATF_TC_BODY(asinf_inf_neg, tc)
187 const float x = -1.0L / 0.0L;
189 if (isnan(asinf(x)) == 0)
190 atf_tc_fail_nonfatal("asinf(-Inf) != NaN");
193 ATF_TC(asinf_inf_pos);
194 ATF_TC_HEAD(asinf_inf_pos, tc)
196 atf_tc_set_md_var(tc, "descr", "Test asinf(+Inf) == NaN");
199 ATF_TC_BODY(asinf_inf_pos, tc)
201 const float x = 1.0L / 0.0L;
203 if (isnan(asinf(x)) == 0)
204 atf_tc_fail_nonfatal("asinf(+Inf) != NaN");
207 ATF_TC(asinf_range);
208 ATF_TC_HEAD(asinf_range, tc)
210 atf_tc_set_md_var(tc, "descr", "Test asinf(x) == NaN, x < -1, x > 1");
213 ATF_TC_BODY(asinf_range, tc)
215 const float x[] = { -1.1, -1.0000001, 1.1, 1.0000001 };
216 size_t i;
218 for (i = 0; i < __arraycount(x); i++) {
220 if (isnan(asinf(x[i])) == 0)
221 atf_tc_fail_nonfatal("asinf(%f) != NaN", x[i]);
225 ATF_TC(asinf_inrange);
226 ATF_TC_HEAD(asinf_inrange, tc)
228 atf_tc_set_md_var(tc, "descr", "Test asinf(x) for some values");
231 ATF_TC_BODY(asinf_inrange, tc)
233 const float eps = 1.0e-6;
234 float x;
235 float y;
236 size_t i;
238 for (i = 0; i < __arraycount(values); i++) {
239 x = values[i].x;
240 y = values[i].y;
241 if (fabs(asinf(x) - y) > eps)
242 atf_tc_fail_nonfatal("asinf(%g) != %g", x, y);
246 ATF_TC(asinf_zero_neg);
247 ATF_TC_HEAD(asinf_zero_neg, tc)
249 atf_tc_set_md_var(tc, "descr", "Test asinf(-0.0) == -0.0");
252 ATF_TC_BODY(asinf_zero_neg, tc)
254 const float x = -0.0L;
255 float y = asinf(x);
257 if (fabsf(y) > 0.0 || signbit(y) == 0)
258 atf_tc_fail_nonfatal("asinf(-0.0) != -0.0");
261 ATF_TC(asinf_zero_pos);
262 ATF_TC_HEAD(asinf_zero_pos, tc)
264 atf_tc_set_md_var(tc, "descr", "Test asinf(+0.0) == +0.0");
267 ATF_TC_BODY(asinf_zero_pos, tc)
269 const float x = 0.0L;
270 float y = asinf(x);
272 if (fabsf(y) > 0.0 || signbit(y) != 0)
273 atf_tc_fail_nonfatal("asinf(+0.0) != +0.0");
276 ATF_TP_ADD_TCS(tp)
279 ATF_TP_ADD_TC(tp, asin_nan);
280 ATF_TP_ADD_TC(tp, asin_inf_neg);
281 ATF_TP_ADD_TC(tp, asin_inf_pos);
282 ATF_TP_ADD_TC(tp, asin_range);
283 ATF_TP_ADD_TC(tp, asin_inrange);
284 ATF_TP_ADD_TC(tp, asin_zero_neg);
285 ATF_TP_ADD_TC(tp, asin_zero_pos);
287 ATF_TP_ADD_TC(tp, asinf_nan);
288 ATF_TP_ADD_TC(tp, asinf_inf_neg);
289 ATF_TP_ADD_TC(tp, asinf_inf_pos);
290 ATF_TP_ADD_TC(tp, asinf_range);
291 ATF_TP_ADD_TC(tp, asinf_inrange);
292 ATF_TP_ADD_TC(tp, asinf_zero_neg);
293 ATF_TP_ADD_TC(tp, asinf_zero_pos);
295 return atf_no_error();