tools/llvm: Do not build with symbols
[minix3.git] / tests / lib / libm / t_cbrt.c
blobcce1b3f94e6020e2e41983f934527d62be9e1bda
1 /* $NetBSD: t_cbrt.c,v 1.2 2013/11/19 19:24:33 joerg 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_cbrt.c,v 1.2 2013/11/19 19:24:33 joerg Exp $");
34 #include <atf-c.h>
35 #include <math.h>
36 #include <stdio.h>
39 * cbrt(3)
41 ATF_TC(cbrt_nan);
42 ATF_TC_HEAD(cbrt_nan, tc)
44 atf_tc_set_md_var(tc, "descr", "Test cbrt(NaN) == NaN");
47 ATF_TC_BODY(cbrt_nan, tc)
49 #ifndef __vax__
50 const double x = 0.0L / 0.0L;
52 ATF_CHECK(isnan(x) != 0);
53 ATF_CHECK(isnan(cbrt(x)) != 0);
54 #endif
57 ATF_TC(cbrt_pow);
58 ATF_TC_HEAD(cbrt_pow, tc)
60 atf_tc_set_md_var(tc, "descr", "Test cbrt(3) vs. pow(3)");
63 ATF_TC_BODY(cbrt_pow, tc)
65 #ifndef __vax__
66 const double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
67 const double eps = 1.0e-14;
68 double y, z;
69 size_t i;
71 for (i = 0; i < __arraycount(x); i++) {
73 y = cbrt(x[i]);
74 z = pow(x[i], 1.0 / 3.0);
76 if (fabs(y - z) > eps)
77 atf_tc_fail_nonfatal("cbrt(%0.03f) != "
78 "pow(%0.03f, 1/3)\n", x[i], x[i]);
80 #endif
83 ATF_TC(cbrt_inf_neg);
84 ATF_TC_HEAD(cbrt_inf_neg, tc)
86 atf_tc_set_md_var(tc, "descr", "Test cbrt(-Inf) == -Inf");
89 ATF_TC_BODY(cbrt_inf_neg, tc)
91 #ifndef __vax__
92 const double x = -1.0L / 0.0L;
93 double y = cbrt(x);
95 ATF_CHECK(isinf(y) != 0);
96 ATF_CHECK(signbit(y) != 0);
97 #endif
100 ATF_TC(cbrt_inf_pos);
101 ATF_TC_HEAD(cbrt_inf_pos, tc)
103 atf_tc_set_md_var(tc, "descr", "Test cbrt(+Inf) == +Inf");
106 ATF_TC_BODY(cbrt_inf_pos, tc)
108 #ifndef __vax__
109 const double x = 1.0L / 0.0L;
110 double y = cbrt(x);
112 ATF_CHECK(isinf(y) != 0);
113 ATF_CHECK(signbit(y) == 0);
114 #endif
117 ATF_TC(cbrt_zero_neg);
118 ATF_TC_HEAD(cbrt_zero_neg, tc)
120 atf_tc_set_md_var(tc, "descr", "Test cbrt(-0.0) == -0.0");
123 ATF_TC_BODY(cbrt_zero_neg, tc)
125 #ifndef __vax__
126 const double x = -0.0L;
127 double y = cbrt(x);
129 if (fabs(y) > 0.0 || signbit(y) == 0)
130 atf_tc_fail_nonfatal("cbrt(-0.0) != -0.0");
131 #endif
134 ATF_TC(cbrt_zero_pos);
135 ATF_TC_HEAD(cbrt_zero_pos, tc)
137 atf_tc_set_md_var(tc, "descr", "Test cbrt(+0.0) == +0.0");
140 ATF_TC_BODY(cbrt_zero_pos, tc)
142 #ifndef __vax__
143 const double x = 0.0L;
144 double y = cbrt(x);
146 if (fabs(y) > 0.0 || signbit(y) != 0)
147 atf_tc_fail_nonfatal("cbrt(+0.0) != +0.0");
148 #endif
152 * cbrtf(3)
154 ATF_TC(cbrtf_nan);
155 ATF_TC_HEAD(cbrtf_nan, tc)
157 atf_tc_set_md_var(tc, "descr", "Test cbrtf(NaN) == NaN");
160 ATF_TC_BODY(cbrtf_nan, tc)
162 #ifndef __vax__
163 const float x = 0.0L / 0.0L;
165 ATF_CHECK(isnan(x) != 0);
166 ATF_CHECK(isnan(cbrtf(x)) != 0);
167 #endif
170 ATF_TC(cbrtf_powf);
171 ATF_TC_HEAD(cbrtf_powf, tc)
173 atf_tc_set_md_var(tc, "descr", "Test cbrtf(3) vs. powf(3)");
176 ATF_TC_BODY(cbrtf_powf, tc)
178 #ifndef __vax__
179 const float x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
180 const float eps = 1.0e-5;
181 float y, z;
182 size_t i;
184 for (i = 0; i < __arraycount(x); i++) {
186 y = cbrtf(x[i]);
187 z = powf(x[i], 1.0 / 3.0);
189 if (fabsf(y - z) > eps)
190 atf_tc_fail_nonfatal("cbrtf(%0.03f) != "
191 "powf(%0.03f, 1/3)\n", x[i], x[i]);
193 #endif
196 ATF_TC(cbrtf_inf_neg);
197 ATF_TC_HEAD(cbrtf_inf_neg, tc)
199 atf_tc_set_md_var(tc, "descr", "Test cbrtf(-Inf) == -Inf");
202 ATF_TC_BODY(cbrtf_inf_neg, tc)
204 #ifndef __vax__
205 const float x = -1.0L / 0.0L;
206 float y = cbrtf(x);
208 ATF_CHECK(isinf(y) != 0);
209 ATF_CHECK(signbit(y) != 0);
210 #endif
213 ATF_TC(cbrtf_inf_pos);
214 ATF_TC_HEAD(cbrtf_inf_pos, tc)
216 atf_tc_set_md_var(tc, "descr", "Test cbrtf(+Inf) == +Inf");
219 ATF_TC_BODY(cbrtf_inf_pos, tc)
221 #ifndef __vax__
222 const float x = 1.0L / 0.0L;
223 float y = cbrtf(x);
225 ATF_CHECK(isinf(y) != 0);
226 ATF_CHECK(signbit(y) == 0);
227 #endif
230 ATF_TC(cbrtf_zero_neg);
231 ATF_TC_HEAD(cbrtf_zero_neg, tc)
233 atf_tc_set_md_var(tc, "descr", "Test cbrtf(-0.0) == -0.0");
236 ATF_TC_BODY(cbrtf_zero_neg, tc)
238 #ifndef __vax__
239 const float x = -0.0L;
240 float y = cbrtf(x);
242 if (fabsf(y) > 0.0 || signbit(y) == 0)
243 atf_tc_fail_nonfatal("cbrtf(-0.0) != -0.0");
244 #endif
247 ATF_TC(cbrtf_zero_pos);
248 ATF_TC_HEAD(cbrtf_zero_pos, tc)
250 atf_tc_set_md_var(tc, "descr", "Test cbrtf(+0.0) == +0.0");
253 ATF_TC_BODY(cbrtf_zero_pos, tc)
255 #ifndef __vax__
256 const float x = 0.0L;
257 float y = cbrtf(x);
259 if (fabsf(y) > 0.0 || signbit(y) != 0)
260 atf_tc_fail_nonfatal("cbrtf(+0.0) != +0.0");
261 #endif
265 * cbrtl(3)
267 ATF_TC(cbrtl_nan);
268 ATF_TC_HEAD(cbrtl_nan, tc)
270 atf_tc_set_md_var(tc, "descr", "Test cbrtl(NaN) == NaN");
273 ATF_TC_BODY(cbrtl_nan, tc)
275 #ifndef __vax__
276 const long double x = 0.0L / 0.0L;
278 ATF_CHECK(isnan(x) != 0);
279 ATF_CHECK(isnan(cbrtl(x)) != 0);
280 #endif
283 ATF_TC(cbrtl_powl);
284 ATF_TC_HEAD(cbrtl_powl, tc)
286 atf_tc_set_md_var(tc, "descr", "Test cbrtl(3) vs. powl(3)");
289 ATF_TC_BODY(cbrtl_powl, tc)
291 #ifndef __vax__
292 const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
293 const long double eps = 1.0e-15;
294 long double y, z;
295 size_t i;
297 for (i = 0; i < __arraycount(x); i++) {
299 y = cbrtl(x[i]);
300 z = powl(x[i], 1.0 / 3.0);
302 if (fabsl(y - z) > eps * fabsl(1 + x[i]))
303 atf_tc_fail_nonfatal("cbrtl(%0.03Lf) != "
304 "powl(%0.03Lf, 1/3)\n", x[i], x[i]);
306 #endif
309 ATF_TC(cbrtl_inf_neg);
310 ATF_TC_HEAD(cbrtl_inf_neg, tc)
312 atf_tc_set_md_var(tc, "descr", "Test cbrtl(-Inf) == -Inf");
315 ATF_TC_BODY(cbrtl_inf_neg, tc)
317 #ifndef __vax__
318 const long double x = -1.0L / 0.0L;
319 long double y = cbrtl(x);
321 ATF_CHECK(isinf(y) != 0);
322 ATF_CHECK(signbit(y) != 0);
323 #endif
326 ATF_TC(cbrtl_inf_pos);
327 ATF_TC_HEAD(cbrtl_inf_pos, tc)
329 atf_tc_set_md_var(tc, "descr", "Test cbrtl(+Inf) == +Inf");
332 ATF_TC_BODY(cbrtl_inf_pos, tc)
334 #ifndef __vax__
335 const long double x = 1.0L / 0.0L;
336 long double y = cbrtl(x);
338 ATF_CHECK(isinf(y) != 0);
339 ATF_CHECK(signbit(y) == 0);
340 #endif
343 ATF_TC(cbrtl_zero_neg);
344 ATF_TC_HEAD(cbrtl_zero_neg, tc)
346 atf_tc_set_md_var(tc, "descr", "Test cbrtl(-0.0) == -0.0");
349 ATF_TC_BODY(cbrtl_zero_neg, tc)
351 #ifndef __vax__
352 const long double x = -0.0L;
353 long double y = cbrtl(x);
355 if (fabsl(y) > 0.0 || signbit(y) == 0)
356 atf_tc_fail_nonfatal("cbrtl(-0.0) != -0.0");
357 #endif
360 ATF_TC(cbrtl_zero_pos);
361 ATF_TC_HEAD(cbrtl_zero_pos, tc)
363 atf_tc_set_md_var(tc, "descr", "Test cbrtl(+0.0) == +0.0");
366 ATF_TC_BODY(cbrtl_zero_pos, tc)
368 #ifndef __vax__
369 const long double x = 0.0L;
370 long double y = cbrtl(x);
372 if (fabsl(y) > 0.0 || signbit(y) != 0)
373 atf_tc_fail_nonfatal("cbrtl(+0.0) != +0.0");
374 #endif
377 ATF_TP_ADD_TCS(tp)
380 ATF_TP_ADD_TC(tp, cbrt_nan);
381 ATF_TP_ADD_TC(tp, cbrt_pow);
382 ATF_TP_ADD_TC(tp, cbrt_inf_neg);
383 ATF_TP_ADD_TC(tp, cbrt_inf_pos);
384 ATF_TP_ADD_TC(tp, cbrt_zero_neg);
385 ATF_TP_ADD_TC(tp, cbrt_zero_pos);
387 ATF_TP_ADD_TC(tp, cbrtf_nan);
388 ATF_TP_ADD_TC(tp, cbrtf_powf);
389 ATF_TP_ADD_TC(tp, cbrtf_inf_neg);
390 ATF_TP_ADD_TC(tp, cbrtf_inf_pos);
391 ATF_TP_ADD_TC(tp, cbrtf_zero_neg);
392 ATF_TP_ADD_TC(tp, cbrtf_zero_pos);
394 ATF_TP_ADD_TC(tp, cbrtl_nan);
395 ATF_TP_ADD_TC(tp, cbrtl_powl);
396 ATF_TP_ADD_TC(tp, cbrtl_inf_neg);
397 ATF_TP_ADD_TC(tp, cbrtl_inf_pos);
398 ATF_TP_ADD_TC(tp, cbrtl_zero_neg);
399 ATF_TP_ADD_TC(tp, cbrtl_zero_pos);
401 return atf_no_error();