1 /* $NetBSD: t_cbrt.c,v 1.3 2014/03/03 10:39:08 martin 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.
31 #include <sys/cdefs.h>
32 __RCSID("$NetBSD: t_cbrt.c,v 1.3 2014/03/03 10:39:08 martin Exp $");
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 const double x = 0.0L / 0.0L;
51 ATF_CHECK(isnan(x) != 0);
52 ATF_CHECK(isnan(cbrt(x)) != 0);
56 ATF_TC_HEAD(cbrt_pow, tc)
58 atf_tc_set_md_var(tc, "descr", "Test cbrt(3) vs. pow(3)");
61 ATF_TC_BODY(cbrt_pow, tc)
63 const double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
64 const double eps = 1.0e-14;
68 for (i = 0; i < __arraycount(x); i++) {
71 z = pow(x[i], 1.0 / 3.0);
73 if (fabs(y - z) > eps)
74 atf_tc_fail_nonfatal("cbrt(%0.03f) != "
75 "pow(%0.03f, 1/3)\n", x[i], x[i]);
80 ATF_TC_HEAD(cbrt_inf_neg, tc)
82 atf_tc_set_md_var(tc, "descr", "Test cbrt(-Inf) == -Inf");
85 ATF_TC_BODY(cbrt_inf_neg, tc)
87 const double x = -1.0L / 0.0L;
90 ATF_CHECK(isinf(y) != 0);
91 ATF_CHECK(signbit(y) != 0);
95 ATF_TC_HEAD(cbrt_inf_pos, tc)
97 atf_tc_set_md_var(tc, "descr", "Test cbrt(+Inf) == +Inf");
100 ATF_TC_BODY(cbrt_inf_pos, tc)
102 const double x = 1.0L / 0.0L;
105 ATF_CHECK(isinf(y) != 0);
106 ATF_CHECK(signbit(y) == 0);
109 ATF_TC(cbrt_zero_neg);
110 ATF_TC_HEAD(cbrt_zero_neg, tc)
112 atf_tc_set_md_var(tc, "descr", "Test cbrt(-0.0) == -0.0");
115 ATF_TC_BODY(cbrt_zero_neg, tc)
117 const double x = -0.0L;
120 if (fabs(y) > 0.0 || signbit(y) == 0)
121 atf_tc_fail_nonfatal("cbrt(-0.0) != -0.0");
124 ATF_TC(cbrt_zero_pos);
125 ATF_TC_HEAD(cbrt_zero_pos, tc)
127 atf_tc_set_md_var(tc, "descr", "Test cbrt(+0.0) == +0.0");
130 ATF_TC_BODY(cbrt_zero_pos, tc)
132 const double x = 0.0L;
135 if (fabs(y) > 0.0 || signbit(y) != 0)
136 atf_tc_fail_nonfatal("cbrt(+0.0) != +0.0");
143 ATF_TC_HEAD(cbrtf_nan, tc)
145 atf_tc_set_md_var(tc, "descr", "Test cbrtf(NaN) == NaN");
148 ATF_TC_BODY(cbrtf_nan, tc)
150 const float x = 0.0L / 0.0L;
152 ATF_CHECK(isnan(x) != 0);
153 ATF_CHECK(isnan(cbrtf(x)) != 0);
157 ATF_TC_HEAD(cbrtf_powf, tc)
159 atf_tc_set_md_var(tc, "descr", "Test cbrtf(3) vs. powf(3)");
162 ATF_TC_BODY(cbrtf_powf, tc)
164 const float x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
165 const float eps = 1.0e-5;
169 for (i = 0; i < __arraycount(x); i++) {
172 z = powf(x[i], 1.0 / 3.0);
174 if (fabsf(y - z) > eps)
175 atf_tc_fail_nonfatal("cbrtf(%0.03f) != "
176 "powf(%0.03f, 1/3)\n", x[i], x[i]);
180 ATF_TC(cbrtf_inf_neg);
181 ATF_TC_HEAD(cbrtf_inf_neg, tc)
183 atf_tc_set_md_var(tc, "descr", "Test cbrtf(-Inf) == -Inf");
186 ATF_TC_BODY(cbrtf_inf_neg, tc)
188 const float x = -1.0L / 0.0L;
191 ATF_CHECK(isinf(y) != 0);
192 ATF_CHECK(signbit(y) != 0);
195 ATF_TC(cbrtf_inf_pos);
196 ATF_TC_HEAD(cbrtf_inf_pos, tc)
198 atf_tc_set_md_var(tc, "descr", "Test cbrtf(+Inf) == +Inf");
201 ATF_TC_BODY(cbrtf_inf_pos, tc)
203 const float x = 1.0L / 0.0L;
206 ATF_CHECK(isinf(y) != 0);
207 ATF_CHECK(signbit(y) == 0);
210 ATF_TC(cbrtf_zero_neg);
211 ATF_TC_HEAD(cbrtf_zero_neg, tc)
213 atf_tc_set_md_var(tc, "descr", "Test cbrtf(-0.0) == -0.0");
216 ATF_TC_BODY(cbrtf_zero_neg, tc)
218 const float x = -0.0L;
221 if (fabsf(y) > 0.0 || signbit(y) == 0)
222 atf_tc_fail_nonfatal("cbrtf(-0.0) != -0.0");
225 ATF_TC(cbrtf_zero_pos);
226 ATF_TC_HEAD(cbrtf_zero_pos, tc)
228 atf_tc_set_md_var(tc, "descr", "Test cbrtf(+0.0) == +0.0");
231 ATF_TC_BODY(cbrtf_zero_pos, tc)
233 const float x = 0.0L;
236 if (fabsf(y) > 0.0 || signbit(y) != 0)
237 atf_tc_fail_nonfatal("cbrtf(+0.0) != +0.0");
240 #if !defined(__FreeBSD__) || LDBL_PREC != 53
245 ATF_TC_HEAD(cbrtl_nan, tc)
247 atf_tc_set_md_var(tc, "descr", "Test cbrtl(NaN) == NaN");
250 ATF_TC_BODY(cbrtl_nan, tc)
252 const long double x = 0.0L / 0.0L;
254 ATF_CHECK(isnan(x) != 0);
255 ATF_CHECK(isnan(cbrtl(x)) != 0);
259 ATF_TC_HEAD(cbrtl_powl, tc)
261 atf_tc_set_md_var(tc, "descr", "Test cbrtl(3) vs. powl(3)");
264 ATF_TC_BODY(cbrtl_powl, tc)
266 const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
267 const long double eps = 1.0e-15;
271 for (i = 0; i < __arraycount(x); i++) {
275 z = powl(x[i], (long double)1.0 / 3.0);
277 z = powl(x[i], 1.0 / 3.0);
280 if (fabsl(y - z) > eps * fabsl(1 + x[i]))
281 atf_tc_fail_nonfatal("cbrtl(%0.03Lf) != "
282 "powl(%0.03Lf, 1/3)\n", x[i], x[i]);
286 ATF_TC(cbrtl_inf_neg);
287 ATF_TC_HEAD(cbrtl_inf_neg, tc)
289 atf_tc_set_md_var(tc, "descr", "Test cbrtl(-Inf) == -Inf");
292 ATF_TC_BODY(cbrtl_inf_neg, tc)
294 const long double x = -1.0L / 0.0L;
295 long double y = cbrtl(x);
297 ATF_CHECK(isinf(y) != 0);
298 ATF_CHECK(signbit(y) != 0);
301 ATF_TC(cbrtl_inf_pos);
302 ATF_TC_HEAD(cbrtl_inf_pos, tc)
304 atf_tc_set_md_var(tc, "descr", "Test cbrtl(+Inf) == +Inf");
307 ATF_TC_BODY(cbrtl_inf_pos, tc)
309 const long double x = 1.0L / 0.0L;
310 long double y = cbrtl(x);
312 ATF_CHECK(isinf(y) != 0);
313 ATF_CHECK(signbit(y) == 0);
316 ATF_TC(cbrtl_zero_neg);
317 ATF_TC_HEAD(cbrtl_zero_neg, tc)
319 atf_tc_set_md_var(tc, "descr", "Test cbrtl(-0.0) == -0.0");
322 ATF_TC_BODY(cbrtl_zero_neg, tc)
324 const long double x = -0.0L;
325 long double y = cbrtl(x);
327 if (fabsl(y) > 0.0 || signbit(y) == 0)
328 atf_tc_fail_nonfatal("cbrtl(-0.0) != -0.0");
331 ATF_TC(cbrtl_zero_pos);
332 ATF_TC_HEAD(cbrtl_zero_pos, tc)
334 atf_tc_set_md_var(tc, "descr", "Test cbrtl(+0.0) == +0.0");
337 ATF_TC_BODY(cbrtl_zero_pos, tc)
339 const long double x = 0.0L;
340 long double y = cbrtl(x);
342 if (fabsl(y) > 0.0 || signbit(y) != 0)
343 atf_tc_fail_nonfatal("cbrtl(+0.0) != +0.0");
350 ATF_TP_ADD_TC(tp, cbrt_nan);
351 ATF_TP_ADD_TC(tp, cbrt_pow);
352 ATF_TP_ADD_TC(tp, cbrt_inf_neg);
353 ATF_TP_ADD_TC(tp, cbrt_inf_pos);
354 ATF_TP_ADD_TC(tp, cbrt_zero_neg);
355 ATF_TP_ADD_TC(tp, cbrt_zero_pos);
357 ATF_TP_ADD_TC(tp, cbrtf_nan);
358 ATF_TP_ADD_TC(tp, cbrtf_powf);
359 ATF_TP_ADD_TC(tp, cbrtf_inf_neg);
360 ATF_TP_ADD_TC(tp, cbrtf_inf_pos);
361 ATF_TP_ADD_TC(tp, cbrtf_zero_neg);
362 ATF_TP_ADD_TC(tp, cbrtf_zero_pos);
364 #if !defined(__FreeBSD__) || LDBL_PREC != 53
365 ATF_TP_ADD_TC(tp, cbrtl_nan);
366 ATF_TP_ADD_TC(tp, cbrtl_powl);
367 ATF_TP_ADD_TC(tp, cbrtl_inf_neg);
368 ATF_TP_ADD_TC(tp, cbrtl_inf_pos);
369 ATF_TP_ADD_TC(tp, cbrtl_zero_neg);
370 ATF_TP_ADD_TC(tp, cbrtl_zero_pos);
373 return atf_no_error();