tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libm / t_sqrt.c
blob4a5e8a080df31362e3b6083c5159e405df7e65d0
1 /* $NetBSD: t_sqrt.c,v 1.5 2013/11/22 17:19:14 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.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_sqrt.c,v 1.5 2013/11/22 17:19:14 martin Exp $");
34 #include <atf-c.h>
35 #include <math.h>
36 #include <float.h>
37 #include <stdio.h>
40 * sqrt(3)
42 ATF_TC(sqrt_nan);
43 ATF_TC_HEAD(sqrt_nan, tc)
45 atf_tc_set_md_var(tc, "descr", "Test sqrt(NaN) == NaN");
48 ATF_TC_BODY(sqrt_nan, tc)
50 #ifndef __vax__
51 const double x = 0.0L / 0.0L;
53 ATF_CHECK(isnan(x) != 0);
54 ATF_CHECK(isnan(sqrt(x)) != 0);
55 #endif
58 ATF_TC(sqrt_pow);
59 ATF_TC_HEAD(sqrt_pow, tc)
61 atf_tc_set_md_var(tc, "descr", "Test sqrt(3) vs. pow(3)");
64 ATF_TC_BODY(sqrt_pow, tc)
66 #ifndef __vax__
67 const double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 };
68 const double eps = 1.0e-40;
69 double y, z;
70 size_t i;
72 for (i = 0; i < __arraycount(x); i++) {
74 y = sqrt(x[i]);
75 z = pow(x[i], 1.0 / 2.0);
77 if (fabs(y - z) > eps)
78 atf_tc_fail_nonfatal("sqrt(%0.03f) != "
79 "pow(%0.03f, 1/2)\n", x[i], x[i]);
81 #endif
84 ATF_TC(sqrt_inf_neg);
85 ATF_TC_HEAD(sqrt_inf_neg, tc)
87 atf_tc_set_md_var(tc, "descr", "Test sqrt(-Inf) == NaN");
90 ATF_TC_BODY(sqrt_inf_neg, tc)
92 #ifndef __vax__
93 const double x = -1.0L / 0.0L;
94 double y = sqrt(x);
96 ATF_CHECK(isnan(y) != 0);
97 #endif
100 ATF_TC(sqrt_inf_pos);
101 ATF_TC_HEAD(sqrt_inf_pos, tc)
103 atf_tc_set_md_var(tc, "descr", "Test sqrt(+Inf) == +Inf");
106 ATF_TC_BODY(sqrt_inf_pos, tc)
108 #ifndef __vax__
109 const double x = 1.0L / 0.0L;
110 double y = sqrt(x);
112 ATF_CHECK(isinf(y) != 0);
113 ATF_CHECK(signbit(y) == 0);
114 #endif
117 ATF_TC(sqrt_zero_neg);
118 ATF_TC_HEAD(sqrt_zero_neg, tc)
120 atf_tc_set_md_var(tc, "descr", "Test sqrt(-0.0) == -0.0");
123 ATF_TC_BODY(sqrt_zero_neg, tc)
125 #ifndef __vax__
126 const double x = -0.0L;
127 double y = sqrt(x);
129 if (fabs(y) > 0.0 || signbit(y) == 0)
130 atf_tc_fail_nonfatal("sqrt(-0.0) != -0.0");
131 #endif
134 ATF_TC(sqrt_zero_pos);
135 ATF_TC_HEAD(sqrt_zero_pos, tc)
137 atf_tc_set_md_var(tc, "descr", "Test sqrt(+0.0) == +0.0");
140 ATF_TC_BODY(sqrt_zero_pos, tc)
142 #ifndef __vax__
143 const double x = 0.0L;
144 double y = sqrt(x);
146 if (fabs(y) > 0.0 || signbit(y) != 0)
147 atf_tc_fail_nonfatal("sqrt(+0.0) != +0.0");
148 #endif
152 * sqrtf(3)
154 ATF_TC(sqrtf_nan);
155 ATF_TC_HEAD(sqrtf_nan, tc)
157 atf_tc_set_md_var(tc, "descr", "Test sqrtf(NaN) == NaN");
160 ATF_TC_BODY(sqrtf_nan, tc)
162 #ifndef __vax__
163 const float x = 0.0L / 0.0L;
165 ATF_CHECK(isnan(x) != 0);
166 ATF_CHECK(isnan(sqrtf(x)) != 0);
167 #endif
170 ATF_TC(sqrtf_powf);
171 ATF_TC_HEAD(sqrtf_powf, tc)
173 atf_tc_set_md_var(tc, "descr", "Test sqrtf(3) vs. powf(3)");
176 ATF_TC_BODY(sqrtf_powf, tc)
178 #ifndef __vax__
179 const float x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 };
180 const float eps = 1.0e-30;
181 volatile float y, z;
182 size_t i;
184 for (i = 0; i < __arraycount(x); i++) {
186 y = sqrtf(x[i]);
187 z = powf(x[i], 1.0 / 2.0);
189 if (fabsf(y - z) > eps)
190 atf_tc_fail_nonfatal("sqrtf(%0.03f) != "
191 "powf(%0.03f, 1/2)\n", x[i], x[i]);
193 #endif
196 ATF_TC(sqrtf_inf_neg);
197 ATF_TC_HEAD(sqrtf_inf_neg, tc)
199 atf_tc_set_md_var(tc, "descr", "Test sqrtf(-Inf) == NaN");
202 ATF_TC_BODY(sqrtf_inf_neg, tc)
204 #ifndef __vax__
205 const float x = -1.0L / 0.0L;
206 float y = sqrtf(x);
208 ATF_CHECK(isnan(y) != 0);
209 #endif
212 ATF_TC(sqrtf_inf_pos);
213 ATF_TC_HEAD(sqrtf_inf_pos, tc)
215 atf_tc_set_md_var(tc, "descr", "Test sqrtf(+Inf) == +Inf");
218 ATF_TC_BODY(sqrtf_inf_pos, tc)
220 #ifndef __vax__
221 const float x = 1.0L / 0.0L;
222 float y = sqrtf(x);
224 ATF_CHECK(isinf(y) != 0);
225 ATF_CHECK(signbit(y) == 0);
226 #endif
229 ATF_TC(sqrtf_zero_neg);
230 ATF_TC_HEAD(sqrtf_zero_neg, tc)
232 atf_tc_set_md_var(tc, "descr", "Test sqrtf(-0.0) == -0.0");
235 ATF_TC_BODY(sqrtf_zero_neg, tc)
237 #ifndef __vax__
238 const float x = -0.0L;
239 float y = sqrtf(x);
241 if (fabsf(y) > 0.0 || signbit(y) == 0)
242 atf_tc_fail_nonfatal("sqrtf(-0.0) != -0.0");
243 #endif
246 ATF_TC(sqrtf_zero_pos);
247 ATF_TC_HEAD(sqrtf_zero_pos, tc)
249 atf_tc_set_md_var(tc, "descr", "Test sqrtf(+0.0) == +0.0");
252 ATF_TC_BODY(sqrtf_zero_pos, tc)
254 #ifndef __vax__
255 const float x = 0.0L;
256 float y = sqrtf(x);
258 if (fabsf(y) > 0.0 || signbit(y) != 0)
259 atf_tc_fail_nonfatal("sqrtf(+0.0) != +0.0");
260 #endif
264 * sqrtl(3)
266 ATF_TC(sqrtl_nan);
267 ATF_TC_HEAD(sqrtl_nan, tc)
269 atf_tc_set_md_var(tc, "descr", "Test sqrtl(NaN) == NaN");
272 ATF_TC_BODY(sqrtl_nan, tc)
274 #ifndef __vax__
275 const long double x = 0.0L / 0.0L;
277 ATF_CHECK(isnan(x) != 0);
278 ATF_CHECK(isnan(sqrtl(x)) != 0);
279 #endif
282 ATF_TC(sqrtl_powl);
283 ATF_TC_HEAD(sqrtl_powl, tc)
285 atf_tc_set_md_var(tc, "descr", "Test sqrtl(3) vs. powl(3)");
288 ATF_TC_BODY(sqrtl_powl, tc)
290 #ifndef __vax__
291 const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 };
292 const long double eps = 5.0*DBL_EPSILON; /* XXX powl == pow for now */
293 volatile long double y, z;
294 size_t i;
296 for (i = 0; i < __arraycount(x); i++) {
298 y = sqrtl(x[i]);
299 z = powl(x[i], 1.0 / 2.0);
301 if (fabsl(y - z) > eps)
302 atf_tc_fail_nonfatal("sqrtl(%0.03Lf) != "
303 "powl(%0.03Lf, 1/2)\n", x[i], x[i]);
305 #endif
308 ATF_TC(sqrtl_inf_neg);
309 ATF_TC_HEAD(sqrtl_inf_neg, tc)
311 atf_tc_set_md_var(tc, "descr", "Test sqrtl(-Inf) == NaN");
314 ATF_TC_BODY(sqrtl_inf_neg, tc)
316 #ifndef __vax__
317 const long double x = -1.0L / 0.0L;
318 long double y = sqrtl(x);
320 ATF_CHECK(isnan(y) != 0);
321 #endif
324 ATF_TC(sqrtl_inf_pos);
325 ATF_TC_HEAD(sqrtl_inf_pos, tc)
327 atf_tc_set_md_var(tc, "descr", "Test sqrtl(+Inf) == +Inf");
330 ATF_TC_BODY(sqrtl_inf_pos, tc)
332 #ifndef __vax__
333 const long double x = 1.0L / 0.0L;
334 long double y = sqrtl(x);
336 ATF_CHECK(isinf(y) != 0);
337 ATF_CHECK(signbit(y) == 0);
338 #endif
341 ATF_TC(sqrtl_zero_neg);
342 ATF_TC_HEAD(sqrtl_zero_neg, tc)
344 atf_tc_set_md_var(tc, "descr", "Test sqrtl(-0.0) == -0.0");
347 ATF_TC_BODY(sqrtl_zero_neg, tc)
349 #ifndef __vax__
350 const long double x = -0.0L;
351 long double y = sqrtl(x);
353 if (fabsl(y) > 0.0 || signbit(y) == 0)
354 atf_tc_fail_nonfatal("sqrtl(-0.0) != -0.0");
355 #endif
358 ATF_TC(sqrtl_zero_pos);
359 ATF_TC_HEAD(sqrtl_zero_pos, tc)
361 atf_tc_set_md_var(tc, "descr", "Test sqrtl(+0.0) == +0.0");
364 ATF_TC_BODY(sqrtl_zero_pos, tc)
366 #ifndef __vax__
367 const long double x = 0.0L;
368 long double y = sqrtl(x);
370 if (fabsl(y) > 0.0 || signbit(y) != 0)
371 atf_tc_fail_nonfatal("sqrtl(+0.0) != +0.0");
372 #endif
375 ATF_TP_ADD_TCS(tp)
378 ATF_TP_ADD_TC(tp, sqrt_nan);
379 ATF_TP_ADD_TC(tp, sqrt_pow);
380 ATF_TP_ADD_TC(tp, sqrt_inf_neg);
381 ATF_TP_ADD_TC(tp, sqrt_inf_pos);
382 ATF_TP_ADD_TC(tp, sqrt_zero_neg);
383 ATF_TP_ADD_TC(tp, sqrt_zero_pos);
385 ATF_TP_ADD_TC(tp, sqrtf_nan);
386 ATF_TP_ADD_TC(tp, sqrtf_powf);
387 ATF_TP_ADD_TC(tp, sqrtf_inf_neg);
388 ATF_TP_ADD_TC(tp, sqrtf_inf_pos);
389 ATF_TP_ADD_TC(tp, sqrtf_zero_neg);
390 ATF_TP_ADD_TC(tp, sqrtf_zero_pos);
392 ATF_TP_ADD_TC(tp, sqrtl_nan);
393 ATF_TP_ADD_TC(tp, sqrtl_powl);
394 ATF_TP_ADD_TC(tp, sqrtl_inf_neg);
395 ATF_TP_ADD_TC(tp, sqrtl_inf_pos);
396 ATF_TP_ADD_TC(tp, sqrtl_zero_neg);
397 ATF_TP_ADD_TC(tp, sqrtl_zero_pos);
399 return atf_no_error();