xref: /freebsd/contrib/netbsd-tests/lib/libm/t_cbrt.c (revision 1ec3feb64826d2a43d41e74684690985bf20e71c)
1*1ec3feb6SAlex Richardson /* $NetBSD: t_cbrt.c,v 1.5 2018/11/15 05:14:20 riastradh Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2011 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
857718be8SEnji Cooper  * by Jukka Ruohonen.
957718be8SEnji Cooper  *
1057718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
1157718be8SEnji Cooper  * modification, are permitted provided that the following conditions
1257718be8SEnji Cooper  * are met:
1357718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1457718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1557718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1657718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1757718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1857718be8SEnji Cooper  *
1957718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2057718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2157718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2257718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2357718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2457718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2557718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2657718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2757718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2857718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2957718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
3057718be8SEnji Cooper  */
3157718be8SEnji Cooper #include <sys/cdefs.h>
32*1ec3feb6SAlex Richardson __RCSID("$NetBSD: t_cbrt.c,v 1.5 2018/11/15 05:14:20 riastradh Exp $");
3357718be8SEnji Cooper 
3457718be8SEnji Cooper #include <atf-c.h>
35*1ec3feb6SAlex Richardson #include <float.h>
3657718be8SEnji Cooper #include <math.h>
3757718be8SEnji Cooper #include <stdio.h>
3857718be8SEnji Cooper 
3957718be8SEnji Cooper /*
4057718be8SEnji Cooper  * cbrt(3)
4157718be8SEnji Cooper  */
4257718be8SEnji Cooper ATF_TC(cbrt_nan);
ATF_TC_HEAD(cbrt_nan,tc)4357718be8SEnji Cooper ATF_TC_HEAD(cbrt_nan, tc)
4457718be8SEnji Cooper {
4557718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrt(NaN) == NaN");
4657718be8SEnji Cooper }
4757718be8SEnji Cooper 
ATF_TC_BODY(cbrt_nan,tc)4857718be8SEnji Cooper ATF_TC_BODY(cbrt_nan, tc)
4957718be8SEnji Cooper {
5057718be8SEnji Cooper 	const double x = 0.0L / 0.0L;
5157718be8SEnji Cooper 
5257718be8SEnji Cooper 	ATF_CHECK(isnan(x) != 0);
5357718be8SEnji Cooper 	ATF_CHECK(isnan(cbrt(x)) != 0);
5457718be8SEnji Cooper }
5557718be8SEnji Cooper 
5657718be8SEnji Cooper ATF_TC(cbrt_pow);
ATF_TC_HEAD(cbrt_pow,tc)5757718be8SEnji Cooper ATF_TC_HEAD(cbrt_pow, tc)
5857718be8SEnji Cooper {
5957718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrt(3) vs. pow(3)");
6057718be8SEnji Cooper }
6157718be8SEnji Cooper 
ATF_TC_BODY(cbrt_pow,tc)6257718be8SEnji Cooper ATF_TC_BODY(cbrt_pow, tc)
6357718be8SEnji Cooper {
6457718be8SEnji Cooper 	const double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
65*1ec3feb6SAlex Richardson 	/* Neither cbrt nor pow is required to be correctly rounded.  */
66*1ec3feb6SAlex Richardson 	const double eps = 2*DBL_EPSILON;
6757718be8SEnji Cooper 	size_t i;
6857718be8SEnji Cooper 
6957718be8SEnji Cooper 	for (i = 0; i < __arraycount(x); i++) {
70*1ec3feb6SAlex Richardson 		double x_cbrt = cbrt(x[i]);
71*1ec3feb6SAlex Richardson 		double x_pow13 = pow(x[i], 1.0 / 3.0);
72*1ec3feb6SAlex Richardson 		bool ok;
7357718be8SEnji Cooper 
74*1ec3feb6SAlex Richardson 		if (x[i] == 0) {
75*1ec3feb6SAlex Richardson 			ok = (x_cbrt == x_pow13);
76*1ec3feb6SAlex Richardson 		} else {
77*1ec3feb6SAlex Richardson 			ok = (fabs((x_cbrt - x_pow13)/x_cbrt) <= eps);
78*1ec3feb6SAlex Richardson 		}
7957718be8SEnji Cooper 
80*1ec3feb6SAlex Richardson 		if (!ok) {
81*1ec3feb6SAlex Richardson 			atf_tc_fail_nonfatal("cbrt(%.17g) = %.17g != "
82*1ec3feb6SAlex Richardson 			    "pow(%.17g, 1/3) = %.17g\n",
83*1ec3feb6SAlex Richardson 			    x[i], x_cbrt, x[i], x_pow13);
84*1ec3feb6SAlex Richardson 		}
8557718be8SEnji Cooper 	}
8657718be8SEnji Cooper }
8757718be8SEnji Cooper 
8857718be8SEnji Cooper ATF_TC(cbrt_inf_neg);
ATF_TC_HEAD(cbrt_inf_neg,tc)8957718be8SEnji Cooper ATF_TC_HEAD(cbrt_inf_neg, tc)
9057718be8SEnji Cooper {
9157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrt(-Inf) == -Inf");
9257718be8SEnji Cooper }
9357718be8SEnji Cooper 
ATF_TC_BODY(cbrt_inf_neg,tc)9457718be8SEnji Cooper ATF_TC_BODY(cbrt_inf_neg, tc)
9557718be8SEnji Cooper {
9657718be8SEnji Cooper 	const double x = -1.0L / 0.0L;
9757718be8SEnji Cooper 	double y = cbrt(x);
9857718be8SEnji Cooper 
9957718be8SEnji Cooper 	ATF_CHECK(isinf(y) != 0);
10057718be8SEnji Cooper 	ATF_CHECK(signbit(y) != 0);
10157718be8SEnji Cooper }
10257718be8SEnji Cooper 
10357718be8SEnji Cooper ATF_TC(cbrt_inf_pos);
ATF_TC_HEAD(cbrt_inf_pos,tc)10457718be8SEnji Cooper ATF_TC_HEAD(cbrt_inf_pos, tc)
10557718be8SEnji Cooper {
10657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrt(+Inf) == +Inf");
10757718be8SEnji Cooper }
10857718be8SEnji Cooper 
ATF_TC_BODY(cbrt_inf_pos,tc)10957718be8SEnji Cooper ATF_TC_BODY(cbrt_inf_pos, tc)
11057718be8SEnji Cooper {
11157718be8SEnji Cooper 	const double x = 1.0L / 0.0L;
11257718be8SEnji Cooper 	double y = cbrt(x);
11357718be8SEnji Cooper 
11457718be8SEnji Cooper 	ATF_CHECK(isinf(y) != 0);
11557718be8SEnji Cooper 	ATF_CHECK(signbit(y) == 0);
11657718be8SEnji Cooper }
11757718be8SEnji Cooper 
11857718be8SEnji Cooper ATF_TC(cbrt_zero_neg);
ATF_TC_HEAD(cbrt_zero_neg,tc)11957718be8SEnji Cooper ATF_TC_HEAD(cbrt_zero_neg, tc)
12057718be8SEnji Cooper {
12157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrt(-0.0) == -0.0");
12257718be8SEnji Cooper }
12357718be8SEnji Cooper 
ATF_TC_BODY(cbrt_zero_neg,tc)12457718be8SEnji Cooper ATF_TC_BODY(cbrt_zero_neg, tc)
12557718be8SEnji Cooper {
12657718be8SEnji Cooper 	const double x = -0.0L;
12757718be8SEnji Cooper 	double y = cbrt(x);
12857718be8SEnji Cooper 
12957718be8SEnji Cooper 	if (fabs(y) > 0.0 || signbit(y) == 0)
13057718be8SEnji Cooper 		atf_tc_fail_nonfatal("cbrt(-0.0) != -0.0");
13157718be8SEnji Cooper }
13257718be8SEnji Cooper 
13357718be8SEnji Cooper ATF_TC(cbrt_zero_pos);
ATF_TC_HEAD(cbrt_zero_pos,tc)13457718be8SEnji Cooper ATF_TC_HEAD(cbrt_zero_pos, tc)
13557718be8SEnji Cooper {
13657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrt(+0.0) == +0.0");
13757718be8SEnji Cooper }
13857718be8SEnji Cooper 
ATF_TC_BODY(cbrt_zero_pos,tc)13957718be8SEnji Cooper ATF_TC_BODY(cbrt_zero_pos, tc)
14057718be8SEnji Cooper {
14157718be8SEnji Cooper 	const double x = 0.0L;
14257718be8SEnji Cooper 	double y = cbrt(x);
14357718be8SEnji Cooper 
14457718be8SEnji Cooper 	if (fabs(y) > 0.0 || signbit(y) != 0)
14557718be8SEnji Cooper 		atf_tc_fail_nonfatal("cbrt(+0.0) != +0.0");
14657718be8SEnji Cooper }
14757718be8SEnji Cooper 
14857718be8SEnji Cooper /*
14957718be8SEnji Cooper  * cbrtf(3)
15057718be8SEnji Cooper  */
15157718be8SEnji Cooper ATF_TC(cbrtf_nan);
ATF_TC_HEAD(cbrtf_nan,tc)15257718be8SEnji Cooper ATF_TC_HEAD(cbrtf_nan, tc)
15357718be8SEnji Cooper {
15457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtf(NaN) == NaN");
15557718be8SEnji Cooper }
15657718be8SEnji Cooper 
ATF_TC_BODY(cbrtf_nan,tc)15757718be8SEnji Cooper ATF_TC_BODY(cbrtf_nan, tc)
15857718be8SEnji Cooper {
15957718be8SEnji Cooper 	const float x = 0.0L / 0.0L;
16057718be8SEnji Cooper 
16157718be8SEnji Cooper 	ATF_CHECK(isnan(x) != 0);
16257718be8SEnji Cooper 	ATF_CHECK(isnan(cbrtf(x)) != 0);
16357718be8SEnji Cooper }
16457718be8SEnji Cooper 
16557718be8SEnji Cooper ATF_TC(cbrtf_powf);
ATF_TC_HEAD(cbrtf_powf,tc)16657718be8SEnji Cooper ATF_TC_HEAD(cbrtf_powf, tc)
16757718be8SEnji Cooper {
16857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtf(3) vs. powf(3)");
16957718be8SEnji Cooper }
17057718be8SEnji Cooper 
ATF_TC_BODY(cbrtf_powf,tc)17157718be8SEnji Cooper ATF_TC_BODY(cbrtf_powf, tc)
17257718be8SEnji Cooper {
17357718be8SEnji Cooper 	const float x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
174*1ec3feb6SAlex Richardson 	/* Neither cbrt nor pow is required to be correctly rounded.  */
175*1ec3feb6SAlex Richardson 	const float eps = 2*FLT_EPSILON;
17657718be8SEnji Cooper 	size_t i;
17757718be8SEnji Cooper 
17857718be8SEnji Cooper 	for (i = 0; i < __arraycount(x); i++) {
179*1ec3feb6SAlex Richardson 		float x_cbrt = cbrtf(x[i]);
180*1ec3feb6SAlex Richardson 		float x_pow13 = powf(x[i], 1.0 / 3.0);
181*1ec3feb6SAlex Richardson 		bool ok;
18257718be8SEnji Cooper 
183*1ec3feb6SAlex Richardson 		if (x[i] == 0) {
184*1ec3feb6SAlex Richardson 			ok = (x_cbrt == x_pow13);
185*1ec3feb6SAlex Richardson 		} else {
186*1ec3feb6SAlex Richardson 			ok = (fabsf((x_cbrt - x_pow13)/x_cbrt) <= eps);
187*1ec3feb6SAlex Richardson 		}
18857718be8SEnji Cooper 
189*1ec3feb6SAlex Richardson 		if (!ok) {
190*1ec3feb6SAlex Richardson 			atf_tc_fail_nonfatal("cbrtf(%.9g) = %.9g. != "
191*1ec3feb6SAlex Richardson 			    "powf(%.9g, 1/3) = %.9g\n",
192*1ec3feb6SAlex Richardson 			    (double)x[i], (double)x_cbrt,
193*1ec3feb6SAlex Richardson 			    (double)x[i], (double)x_pow13);
194*1ec3feb6SAlex Richardson 		}
19557718be8SEnji Cooper 	}
19657718be8SEnji Cooper }
19757718be8SEnji Cooper 
19857718be8SEnji Cooper ATF_TC(cbrtf_inf_neg);
ATF_TC_HEAD(cbrtf_inf_neg,tc)19957718be8SEnji Cooper ATF_TC_HEAD(cbrtf_inf_neg, tc)
20057718be8SEnji Cooper {
20157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtf(-Inf) == -Inf");
20257718be8SEnji Cooper }
20357718be8SEnji Cooper 
ATF_TC_BODY(cbrtf_inf_neg,tc)20457718be8SEnji Cooper ATF_TC_BODY(cbrtf_inf_neg, tc)
20557718be8SEnji Cooper {
20657718be8SEnji Cooper 	const float x = -1.0L / 0.0L;
20757718be8SEnji Cooper 	float y = cbrtf(x);
20857718be8SEnji Cooper 
20957718be8SEnji Cooper 	ATF_CHECK(isinf(y) != 0);
21057718be8SEnji Cooper 	ATF_CHECK(signbit(y) != 0);
21157718be8SEnji Cooper }
21257718be8SEnji Cooper 
21357718be8SEnji Cooper ATF_TC(cbrtf_inf_pos);
ATF_TC_HEAD(cbrtf_inf_pos,tc)21457718be8SEnji Cooper ATF_TC_HEAD(cbrtf_inf_pos, tc)
21557718be8SEnji Cooper {
21657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtf(+Inf) == +Inf");
21757718be8SEnji Cooper }
21857718be8SEnji Cooper 
ATF_TC_BODY(cbrtf_inf_pos,tc)21957718be8SEnji Cooper ATF_TC_BODY(cbrtf_inf_pos, tc)
22057718be8SEnji Cooper {
22157718be8SEnji Cooper 	const float x = 1.0L / 0.0L;
22257718be8SEnji Cooper 	float y = cbrtf(x);
22357718be8SEnji Cooper 
22457718be8SEnji Cooper 	ATF_CHECK(isinf(y) != 0);
22557718be8SEnji Cooper 	ATF_CHECK(signbit(y) == 0);
22657718be8SEnji Cooper }
22757718be8SEnji Cooper 
22857718be8SEnji Cooper ATF_TC(cbrtf_zero_neg);
ATF_TC_HEAD(cbrtf_zero_neg,tc)22957718be8SEnji Cooper ATF_TC_HEAD(cbrtf_zero_neg, tc)
23057718be8SEnji Cooper {
23157718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtf(-0.0) == -0.0");
23257718be8SEnji Cooper }
23357718be8SEnji Cooper 
ATF_TC_BODY(cbrtf_zero_neg,tc)23457718be8SEnji Cooper ATF_TC_BODY(cbrtf_zero_neg, tc)
23557718be8SEnji Cooper {
23657718be8SEnji Cooper 	const float x = -0.0L;
23757718be8SEnji Cooper 	float y = cbrtf(x);
23857718be8SEnji Cooper 
23957718be8SEnji Cooper 	if (fabsf(y) > 0.0 || signbit(y) == 0)
24057718be8SEnji Cooper 		atf_tc_fail_nonfatal("cbrtf(-0.0) != -0.0");
24157718be8SEnji Cooper }
24257718be8SEnji Cooper 
24357718be8SEnji Cooper ATF_TC(cbrtf_zero_pos);
ATF_TC_HEAD(cbrtf_zero_pos,tc)24457718be8SEnji Cooper ATF_TC_HEAD(cbrtf_zero_pos, tc)
24557718be8SEnji Cooper {
24657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtf(+0.0) == +0.0");
24757718be8SEnji Cooper }
24857718be8SEnji Cooper 
ATF_TC_BODY(cbrtf_zero_pos,tc)24957718be8SEnji Cooper ATF_TC_BODY(cbrtf_zero_pos, tc)
25057718be8SEnji Cooper {
25157718be8SEnji Cooper 	const float x = 0.0L;
25257718be8SEnji Cooper 	float y = cbrtf(x);
25357718be8SEnji Cooper 
25457718be8SEnji Cooper 	if (fabsf(y) > 0.0 || signbit(y) != 0)
25557718be8SEnji Cooper 		atf_tc_fail_nonfatal("cbrtf(+0.0) != +0.0");
25657718be8SEnji Cooper }
25757718be8SEnji Cooper 
2581268301aSEnji Cooper #if !defined(__FreeBSD__) || LDBL_PREC != 53
25957718be8SEnji Cooper /*
26057718be8SEnji Cooper  * cbrtl(3)
26157718be8SEnji Cooper  */
26257718be8SEnji Cooper ATF_TC(cbrtl_nan);
ATF_TC_HEAD(cbrtl_nan,tc)26357718be8SEnji Cooper ATF_TC_HEAD(cbrtl_nan, tc)
26457718be8SEnji Cooper {
26557718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtl(NaN) == NaN");
26657718be8SEnji Cooper }
26757718be8SEnji Cooper 
ATF_TC_BODY(cbrtl_nan,tc)26857718be8SEnji Cooper ATF_TC_BODY(cbrtl_nan, tc)
26957718be8SEnji Cooper {
27057718be8SEnji Cooper 	const long double x = 0.0L / 0.0L;
27157718be8SEnji Cooper 
27257718be8SEnji Cooper 	ATF_CHECK(isnan(x) != 0);
27357718be8SEnji Cooper 	ATF_CHECK(isnan(cbrtl(x)) != 0);
27457718be8SEnji Cooper }
27557718be8SEnji Cooper 
27657718be8SEnji Cooper ATF_TC(cbrtl_powl);
ATF_TC_HEAD(cbrtl_powl,tc)27757718be8SEnji Cooper ATF_TC_HEAD(cbrtl_powl, tc)
27857718be8SEnji Cooper {
27957718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtl(3) vs. powl(3)");
28057718be8SEnji Cooper }
28157718be8SEnji Cooper 
ATF_TC_BODY(cbrtl_powl,tc)28257718be8SEnji Cooper ATF_TC_BODY(cbrtl_powl, tc)
28357718be8SEnji Cooper {
28457718be8SEnji Cooper 	const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
285*1ec3feb6SAlex Richardson 	/* Neither cbrt nor pow is required to be correctly rounded.  */
286*1ec3feb6SAlex Richardson 	const long double eps = 2*LDBL_EPSILON;
28757718be8SEnji Cooper 	size_t i;
28857718be8SEnji Cooper 
289bc8fc007SDimitry Andric #if defined(__amd64__) && defined(__clang__) && __clang_major__ >= 7 && \
29083ff5d5dSAlex Richardson     __clang_major__ < 10 && __FreeBSD_cc_version < 1300002
29183ff5d5dSAlex Richardson 	atf_tc_expect_fail("test fails with clang 7-9 - bug 234040");
29224df7b15SLi-Wen Hsu #endif
29357718be8SEnji Cooper 	for (i = 0; i < __arraycount(x); i++) {
294*1ec3feb6SAlex Richardson 		long double x_cbrt = cbrtl(x[i]);
2951268301aSEnji Cooper #ifdef __FreeBSD__
296*1ec3feb6SAlex Richardson 		/*
297*1ec3feb6SAlex Richardson 		 * NetBSD doesn't have a real powl/cbrtl implementation, they
298*1ec3feb6SAlex Richardson 		 * just call the double version. On FreeBSD we have a real
299*1ec3feb6SAlex Richardson 		 * powl implementation so we have to cast the second argument
300*1ec3feb6SAlex Richardson 		 * to long double before dividing to get a more precise
301*1ec3feb6SAlex Richardson 		 * approximation of 1/3.
302*1ec3feb6SAlex Richardson 		 * TODO: upstream this diff.
303*1ec3feb6SAlex Richardson 		 */
304*1ec3feb6SAlex Richardson 		long double x_pow13 = powl(x[i], (long double)1.0 / 3.0);
3051268301aSEnji Cooper #else
306*1ec3feb6SAlex Richardson 		long double x_pow13 = powl(x[i], 1.0 / 3.0);
3071268301aSEnji Cooper #endif
308*1ec3feb6SAlex Richardson 		bool ok;
30957718be8SEnji Cooper 
310*1ec3feb6SAlex Richardson 		if (x[i] == 0) {
311*1ec3feb6SAlex Richardson 			ok = (x_cbrt == x_pow13);
312*1ec3feb6SAlex Richardson 		} else {
313*1ec3feb6SAlex Richardson 			ok = (fabsl((x_cbrt - x_pow13)/x_cbrt) <= eps);
314*1ec3feb6SAlex Richardson 		}
315*1ec3feb6SAlex Richardson 
316*1ec3feb6SAlex Richardson 		if (!ok) {
317*1ec3feb6SAlex Richardson 			atf_tc_fail_nonfatal("cbrtl(%.35Lg) = %.35Lg != "
318*1ec3feb6SAlex Richardson 			    "powl(%.35Lg, 1/3) = %.35Lg\n",
319*1ec3feb6SAlex Richardson 			    x[i], x_cbrt, x[i], x_pow13);
320*1ec3feb6SAlex Richardson 		}
32157718be8SEnji Cooper 	}
32257718be8SEnji Cooper }
32357718be8SEnji Cooper 
32457718be8SEnji Cooper ATF_TC(cbrtl_inf_neg);
ATF_TC_HEAD(cbrtl_inf_neg,tc)32557718be8SEnji Cooper ATF_TC_HEAD(cbrtl_inf_neg, tc)
32657718be8SEnji Cooper {
32757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtl(-Inf) == -Inf");
32857718be8SEnji Cooper }
32957718be8SEnji Cooper 
ATF_TC_BODY(cbrtl_inf_neg,tc)33057718be8SEnji Cooper ATF_TC_BODY(cbrtl_inf_neg, tc)
33157718be8SEnji Cooper {
33257718be8SEnji Cooper 	const long double x = -1.0L / 0.0L;
33357718be8SEnji Cooper 	long double y = cbrtl(x);
33457718be8SEnji Cooper 
33557718be8SEnji Cooper 	ATF_CHECK(isinf(y) != 0);
33657718be8SEnji Cooper 	ATF_CHECK(signbit(y) != 0);
33757718be8SEnji Cooper }
33857718be8SEnji Cooper 
33957718be8SEnji Cooper ATF_TC(cbrtl_inf_pos);
ATF_TC_HEAD(cbrtl_inf_pos,tc)34057718be8SEnji Cooper ATF_TC_HEAD(cbrtl_inf_pos, tc)
34157718be8SEnji Cooper {
34257718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtl(+Inf) == +Inf");
34357718be8SEnji Cooper }
34457718be8SEnji Cooper 
ATF_TC_BODY(cbrtl_inf_pos,tc)34557718be8SEnji Cooper ATF_TC_BODY(cbrtl_inf_pos, tc)
34657718be8SEnji Cooper {
34757718be8SEnji Cooper 	const long double x = 1.0L / 0.0L;
34857718be8SEnji Cooper 	long double y = cbrtl(x);
34957718be8SEnji Cooper 
35057718be8SEnji Cooper 	ATF_CHECK(isinf(y) != 0);
35157718be8SEnji Cooper 	ATF_CHECK(signbit(y) == 0);
35257718be8SEnji Cooper }
35357718be8SEnji Cooper 
35457718be8SEnji Cooper ATF_TC(cbrtl_zero_neg);
ATF_TC_HEAD(cbrtl_zero_neg,tc)35557718be8SEnji Cooper ATF_TC_HEAD(cbrtl_zero_neg, tc)
35657718be8SEnji Cooper {
35757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtl(-0.0) == -0.0");
35857718be8SEnji Cooper }
35957718be8SEnji Cooper 
ATF_TC_BODY(cbrtl_zero_neg,tc)36057718be8SEnji Cooper ATF_TC_BODY(cbrtl_zero_neg, tc)
36157718be8SEnji Cooper {
36257718be8SEnji Cooper 	const long double x = -0.0L;
36357718be8SEnji Cooper 	long double y = cbrtl(x);
36457718be8SEnji Cooper 
36557718be8SEnji Cooper 	if (fabsl(y) > 0.0 || signbit(y) == 0)
36657718be8SEnji Cooper 		atf_tc_fail_nonfatal("cbrtl(-0.0) != -0.0");
36757718be8SEnji Cooper }
36857718be8SEnji Cooper 
36957718be8SEnji Cooper ATF_TC(cbrtl_zero_pos);
ATF_TC_HEAD(cbrtl_zero_pos,tc)37057718be8SEnji Cooper ATF_TC_HEAD(cbrtl_zero_pos, tc)
37157718be8SEnji Cooper {
37257718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Test cbrtl(+0.0) == +0.0");
37357718be8SEnji Cooper }
37457718be8SEnji Cooper 
ATF_TC_BODY(cbrtl_zero_pos,tc)37557718be8SEnji Cooper ATF_TC_BODY(cbrtl_zero_pos, tc)
37657718be8SEnji Cooper {
37757718be8SEnji Cooper 	const long double x = 0.0L;
37857718be8SEnji Cooper 	long double y = cbrtl(x);
37957718be8SEnji Cooper 
38057718be8SEnji Cooper 	if (fabsl(y) > 0.0 || signbit(y) != 0)
38157718be8SEnji Cooper 		atf_tc_fail_nonfatal("cbrtl(+0.0) != +0.0");
38257718be8SEnji Cooper }
3831268301aSEnji Cooper #endif
38457718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)38557718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
38657718be8SEnji Cooper {
38757718be8SEnji Cooper 
38857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrt_nan);
38957718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrt_pow);
39057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrt_inf_neg);
39157718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrt_inf_pos);
39257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrt_zero_neg);
39357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrt_zero_pos);
39457718be8SEnji Cooper 
39557718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtf_nan);
39657718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtf_powf);
39757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtf_inf_neg);
39857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtf_inf_pos);
39957718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtf_zero_neg);
40057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtf_zero_pos);
40157718be8SEnji Cooper 
4021268301aSEnji Cooper #if !defined(__FreeBSD__) || LDBL_PREC != 53
40357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtl_nan);
40457718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtl_powl);
40557718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtl_inf_neg);
40657718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtl_inf_pos);
40757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtl_zero_neg);
40857718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, cbrtl_zero_pos);
4091268301aSEnji Cooper #endif
41057718be8SEnji Cooper 
41157718be8SEnji Cooper 	return atf_no_error();
41257718be8SEnji Cooper }
413