xref: /minix3/tests/lib/libm/t_sqrt.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_sqrt.c,v 1.7 2014/03/12 21:40:07 martin Exp $ */
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc  * Copyright (c) 2011 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc  * All rights reserved.
611be35a1SLionel Sambuc  *
711be35a1SLionel Sambuc  * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc  * by Jukka Ruohonen.
911be35a1SLionel Sambuc  *
1011be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc  * are met:
1311be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc  *
1911be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc  * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc  */
3111be35a1SLionel Sambuc #include <sys/cdefs.h>
32*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_sqrt.c,v 1.7 2014/03/12 21:40:07 martin Exp $");
3311be35a1SLionel Sambuc 
3411be35a1SLionel Sambuc #include <atf-c.h>
3511be35a1SLionel Sambuc #include <math.h>
3684d9c625SLionel Sambuc #include <float.h>
3711be35a1SLionel Sambuc #include <stdio.h>
3811be35a1SLionel Sambuc 
3911be35a1SLionel Sambuc /*
4011be35a1SLionel Sambuc  * sqrt(3)
4111be35a1SLionel Sambuc  */
4211be35a1SLionel Sambuc ATF_TC(sqrt_nan);
ATF_TC_HEAD(sqrt_nan,tc)4311be35a1SLionel Sambuc ATF_TC_HEAD(sqrt_nan, tc)
4411be35a1SLionel Sambuc {
4511be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrt(NaN) == NaN");
4611be35a1SLionel Sambuc }
4711be35a1SLionel Sambuc 
ATF_TC_BODY(sqrt_nan,tc)4811be35a1SLionel Sambuc ATF_TC_BODY(sqrt_nan, tc)
4911be35a1SLionel Sambuc {
5011be35a1SLionel Sambuc 	const double x = 0.0L / 0.0L;
5111be35a1SLionel Sambuc 
5211be35a1SLionel Sambuc 	ATF_CHECK(isnan(x) != 0);
5311be35a1SLionel Sambuc 	ATF_CHECK(isnan(sqrt(x)) != 0);
5411be35a1SLionel Sambuc }
5511be35a1SLionel Sambuc 
5611be35a1SLionel Sambuc ATF_TC(sqrt_pow);
ATF_TC_HEAD(sqrt_pow,tc)5711be35a1SLionel Sambuc ATF_TC_HEAD(sqrt_pow, tc)
5811be35a1SLionel Sambuc {
5911be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrt(3) vs. pow(3)");
6011be35a1SLionel Sambuc }
6111be35a1SLionel Sambuc 
ATF_TC_BODY(sqrt_pow,tc)6211be35a1SLionel Sambuc ATF_TC_BODY(sqrt_pow, tc)
6311be35a1SLionel Sambuc {
6411be35a1SLionel Sambuc 	const double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 };
65*0a6a1f1dSLionel Sambuc #if __DBL_MIN_10_EXP__ <= -40
6611be35a1SLionel Sambuc 	const double eps = 1.0e-40;
67*0a6a1f1dSLionel Sambuc #else
68*0a6a1f1dSLionel Sambuc 	const double eps = __DBL_MIN__*4.0;
69*0a6a1f1dSLionel Sambuc #endif
7011be35a1SLionel Sambuc 	double y, z;
7111be35a1SLionel Sambuc 	size_t i;
7211be35a1SLionel Sambuc 
7311be35a1SLionel Sambuc 	for (i = 0; i < __arraycount(x); i++) {
7411be35a1SLionel Sambuc 
7511be35a1SLionel Sambuc 		y = sqrt(x[i]);
7611be35a1SLionel Sambuc 		z = pow(x[i], 1.0 / 2.0);
7711be35a1SLionel Sambuc 
7811be35a1SLionel Sambuc 		if (fabs(y - z) > eps)
7911be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("sqrt(%0.03f) != "
8011be35a1SLionel Sambuc 			    "pow(%0.03f, 1/2)\n", x[i], x[i]);
8111be35a1SLionel Sambuc 	}
8211be35a1SLionel Sambuc }
8311be35a1SLionel Sambuc 
8411be35a1SLionel Sambuc ATF_TC(sqrt_inf_neg);
ATF_TC_HEAD(sqrt_inf_neg,tc)8511be35a1SLionel Sambuc ATF_TC_HEAD(sqrt_inf_neg, tc)
8611be35a1SLionel Sambuc {
8711be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrt(-Inf) == NaN");
8811be35a1SLionel Sambuc }
8911be35a1SLionel Sambuc 
ATF_TC_BODY(sqrt_inf_neg,tc)9011be35a1SLionel Sambuc ATF_TC_BODY(sqrt_inf_neg, tc)
9111be35a1SLionel Sambuc {
9211be35a1SLionel Sambuc 	const double x = -1.0L / 0.0L;
9311be35a1SLionel Sambuc 	double y = sqrt(x);
9411be35a1SLionel Sambuc 
9511be35a1SLionel Sambuc 	ATF_CHECK(isnan(y) != 0);
9611be35a1SLionel Sambuc }
9711be35a1SLionel Sambuc 
9811be35a1SLionel Sambuc ATF_TC(sqrt_inf_pos);
ATF_TC_HEAD(sqrt_inf_pos,tc)9911be35a1SLionel Sambuc ATF_TC_HEAD(sqrt_inf_pos, tc)
10011be35a1SLionel Sambuc {
10111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrt(+Inf) == +Inf");
10211be35a1SLionel Sambuc }
10311be35a1SLionel Sambuc 
ATF_TC_BODY(sqrt_inf_pos,tc)10411be35a1SLionel Sambuc ATF_TC_BODY(sqrt_inf_pos, tc)
10511be35a1SLionel Sambuc {
10611be35a1SLionel Sambuc 	const double x = 1.0L / 0.0L;
10711be35a1SLionel Sambuc 	double y = sqrt(x);
10811be35a1SLionel Sambuc 
10911be35a1SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
11011be35a1SLionel Sambuc 	ATF_CHECK(signbit(y) == 0);
11111be35a1SLionel Sambuc }
11211be35a1SLionel Sambuc 
11311be35a1SLionel Sambuc ATF_TC(sqrt_zero_neg);
ATF_TC_HEAD(sqrt_zero_neg,tc)11411be35a1SLionel Sambuc ATF_TC_HEAD(sqrt_zero_neg, tc)
11511be35a1SLionel Sambuc {
11611be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrt(-0.0) == -0.0");
11711be35a1SLionel Sambuc }
11811be35a1SLionel Sambuc 
ATF_TC_BODY(sqrt_zero_neg,tc)11911be35a1SLionel Sambuc ATF_TC_BODY(sqrt_zero_neg, tc)
12011be35a1SLionel Sambuc {
12111be35a1SLionel Sambuc 	const double x = -0.0L;
12211be35a1SLionel Sambuc 	double y = sqrt(x);
12311be35a1SLionel Sambuc 
12411be35a1SLionel Sambuc 	if (fabs(y) > 0.0 || signbit(y) == 0)
12511be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sqrt(-0.0) != -0.0");
12611be35a1SLionel Sambuc }
12711be35a1SLionel Sambuc 
12811be35a1SLionel Sambuc ATF_TC(sqrt_zero_pos);
ATF_TC_HEAD(sqrt_zero_pos,tc)12911be35a1SLionel Sambuc ATF_TC_HEAD(sqrt_zero_pos, tc)
13011be35a1SLionel Sambuc {
13111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrt(+0.0) == +0.0");
13211be35a1SLionel Sambuc }
13311be35a1SLionel Sambuc 
ATF_TC_BODY(sqrt_zero_pos,tc)13411be35a1SLionel Sambuc ATF_TC_BODY(sqrt_zero_pos, tc)
13511be35a1SLionel Sambuc {
13611be35a1SLionel Sambuc 	const double x = 0.0L;
13711be35a1SLionel Sambuc 	double y = sqrt(x);
13811be35a1SLionel Sambuc 
13911be35a1SLionel Sambuc 	if (fabs(y) > 0.0 || signbit(y) != 0)
14011be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sqrt(+0.0) != +0.0");
14111be35a1SLionel Sambuc }
14211be35a1SLionel Sambuc 
14311be35a1SLionel Sambuc /*
14411be35a1SLionel Sambuc  * sqrtf(3)
14511be35a1SLionel Sambuc  */
14611be35a1SLionel Sambuc ATF_TC(sqrtf_nan);
ATF_TC_HEAD(sqrtf_nan,tc)14711be35a1SLionel Sambuc ATF_TC_HEAD(sqrtf_nan, tc)
14811be35a1SLionel Sambuc {
14911be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtf(NaN) == NaN");
15011be35a1SLionel Sambuc }
15111be35a1SLionel Sambuc 
ATF_TC_BODY(sqrtf_nan,tc)15211be35a1SLionel Sambuc ATF_TC_BODY(sqrtf_nan, tc)
15311be35a1SLionel Sambuc {
15411be35a1SLionel Sambuc 	const float x = 0.0L / 0.0L;
15511be35a1SLionel Sambuc 
15611be35a1SLionel Sambuc 	ATF_CHECK(isnan(x) != 0);
15711be35a1SLionel Sambuc 	ATF_CHECK(isnan(sqrtf(x)) != 0);
15811be35a1SLionel Sambuc }
15911be35a1SLionel Sambuc 
16011be35a1SLionel Sambuc ATF_TC(sqrtf_powf);
ATF_TC_HEAD(sqrtf_powf,tc)16111be35a1SLionel Sambuc ATF_TC_HEAD(sqrtf_powf, tc)
16211be35a1SLionel Sambuc {
16311be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtf(3) vs. powf(3)");
16411be35a1SLionel Sambuc }
16511be35a1SLionel Sambuc 
ATF_TC_BODY(sqrtf_powf,tc)16611be35a1SLionel Sambuc ATF_TC_BODY(sqrtf_powf, tc)
16711be35a1SLionel Sambuc {
16811be35a1SLionel Sambuc 	const float x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 };
16911be35a1SLionel Sambuc 	const float eps = 1.0e-30;
17011be35a1SLionel Sambuc 	volatile float y, z;
17111be35a1SLionel Sambuc 	size_t i;
17211be35a1SLionel Sambuc 
17311be35a1SLionel Sambuc 	for (i = 0; i < __arraycount(x); i++) {
17411be35a1SLionel Sambuc 
17511be35a1SLionel Sambuc 		y = sqrtf(x[i]);
17611be35a1SLionel Sambuc 		z = powf(x[i], 1.0 / 2.0);
17711be35a1SLionel Sambuc 
17811be35a1SLionel Sambuc 		if (fabsf(y - z) > eps)
17911be35a1SLionel Sambuc 			atf_tc_fail_nonfatal("sqrtf(%0.03f) != "
18011be35a1SLionel Sambuc 			    "powf(%0.03f, 1/2)\n", x[i], x[i]);
18111be35a1SLionel Sambuc 	}
18211be35a1SLionel Sambuc }
18311be35a1SLionel Sambuc 
18411be35a1SLionel Sambuc ATF_TC(sqrtf_inf_neg);
ATF_TC_HEAD(sqrtf_inf_neg,tc)18511be35a1SLionel Sambuc ATF_TC_HEAD(sqrtf_inf_neg, tc)
18611be35a1SLionel Sambuc {
18711be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtf(-Inf) == NaN");
18811be35a1SLionel Sambuc }
18911be35a1SLionel Sambuc 
ATF_TC_BODY(sqrtf_inf_neg,tc)19011be35a1SLionel Sambuc ATF_TC_BODY(sqrtf_inf_neg, tc)
19111be35a1SLionel Sambuc {
19211be35a1SLionel Sambuc 	const float x = -1.0L / 0.0L;
19311be35a1SLionel Sambuc 	float y = sqrtf(x);
19411be35a1SLionel Sambuc 
19511be35a1SLionel Sambuc 	ATF_CHECK(isnan(y) != 0);
19611be35a1SLionel Sambuc }
19711be35a1SLionel Sambuc 
19811be35a1SLionel Sambuc ATF_TC(sqrtf_inf_pos);
ATF_TC_HEAD(sqrtf_inf_pos,tc)19911be35a1SLionel Sambuc ATF_TC_HEAD(sqrtf_inf_pos, tc)
20011be35a1SLionel Sambuc {
20111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtf(+Inf) == +Inf");
20211be35a1SLionel Sambuc }
20311be35a1SLionel Sambuc 
ATF_TC_BODY(sqrtf_inf_pos,tc)20411be35a1SLionel Sambuc ATF_TC_BODY(sqrtf_inf_pos, tc)
20511be35a1SLionel Sambuc {
20611be35a1SLionel Sambuc 	const float x = 1.0L / 0.0L;
20711be35a1SLionel Sambuc 	float y = sqrtf(x);
20811be35a1SLionel Sambuc 
20911be35a1SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
21011be35a1SLionel Sambuc 	ATF_CHECK(signbit(y) == 0);
21111be35a1SLionel Sambuc }
21211be35a1SLionel Sambuc 
21311be35a1SLionel Sambuc ATF_TC(sqrtf_zero_neg);
ATF_TC_HEAD(sqrtf_zero_neg,tc)21411be35a1SLionel Sambuc ATF_TC_HEAD(sqrtf_zero_neg, tc)
21511be35a1SLionel Sambuc {
21611be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtf(-0.0) == -0.0");
21711be35a1SLionel Sambuc }
21811be35a1SLionel Sambuc 
ATF_TC_BODY(sqrtf_zero_neg,tc)21911be35a1SLionel Sambuc ATF_TC_BODY(sqrtf_zero_neg, tc)
22011be35a1SLionel Sambuc {
22111be35a1SLionel Sambuc 	const float x = -0.0L;
22211be35a1SLionel Sambuc 	float y = sqrtf(x);
22311be35a1SLionel Sambuc 
22411be35a1SLionel Sambuc 	if (fabsf(y) > 0.0 || signbit(y) == 0)
22511be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sqrtf(-0.0) != -0.0");
22611be35a1SLionel Sambuc }
22711be35a1SLionel Sambuc 
22811be35a1SLionel Sambuc ATF_TC(sqrtf_zero_pos);
ATF_TC_HEAD(sqrtf_zero_pos,tc)22911be35a1SLionel Sambuc ATF_TC_HEAD(sqrtf_zero_pos, tc)
23011be35a1SLionel Sambuc {
23111be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtf(+0.0) == +0.0");
23211be35a1SLionel Sambuc }
23311be35a1SLionel Sambuc 
ATF_TC_BODY(sqrtf_zero_pos,tc)23411be35a1SLionel Sambuc ATF_TC_BODY(sqrtf_zero_pos, tc)
23511be35a1SLionel Sambuc {
23611be35a1SLionel Sambuc 	const float x = 0.0L;
23711be35a1SLionel Sambuc 	float y = sqrtf(x);
23811be35a1SLionel Sambuc 
23911be35a1SLionel Sambuc 	if (fabsf(y) > 0.0 || signbit(y) != 0)
24011be35a1SLionel Sambuc 		atf_tc_fail_nonfatal("sqrtf(+0.0) != +0.0");
24111be35a1SLionel Sambuc }
24211be35a1SLionel Sambuc 
24384d9c625SLionel Sambuc /*
24484d9c625SLionel Sambuc  * sqrtl(3)
24584d9c625SLionel Sambuc  */
24684d9c625SLionel Sambuc ATF_TC(sqrtl_nan);
ATF_TC_HEAD(sqrtl_nan,tc)24784d9c625SLionel Sambuc ATF_TC_HEAD(sqrtl_nan, tc)
24884d9c625SLionel Sambuc {
24984d9c625SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtl(NaN) == NaN");
25084d9c625SLionel Sambuc }
25184d9c625SLionel Sambuc 
ATF_TC_BODY(sqrtl_nan,tc)25284d9c625SLionel Sambuc ATF_TC_BODY(sqrtl_nan, tc)
25384d9c625SLionel Sambuc {
25484d9c625SLionel Sambuc 	const long double x = 0.0L / 0.0L;
25584d9c625SLionel Sambuc 
25684d9c625SLionel Sambuc 	ATF_CHECK(isnan(x) != 0);
25784d9c625SLionel Sambuc 	ATF_CHECK(isnan(sqrtl(x)) != 0);
25884d9c625SLionel Sambuc }
25984d9c625SLionel Sambuc 
26084d9c625SLionel Sambuc ATF_TC(sqrtl_powl);
ATF_TC_HEAD(sqrtl_powl,tc)26184d9c625SLionel Sambuc ATF_TC_HEAD(sqrtl_powl, tc)
26284d9c625SLionel Sambuc {
26384d9c625SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtl(3) vs. powl(3)");
26484d9c625SLionel Sambuc }
26584d9c625SLionel Sambuc 
ATF_TC_BODY(sqrtl_powl,tc)26684d9c625SLionel Sambuc ATF_TC_BODY(sqrtl_powl, tc)
26784d9c625SLionel Sambuc {
26884d9c625SLionel Sambuc 	const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.9999 };
26984d9c625SLionel Sambuc 	const long double eps = 5.0*DBL_EPSILON; /* XXX powl == pow for now */
27084d9c625SLionel Sambuc 	volatile long double y, z;
27184d9c625SLionel Sambuc 	size_t i;
27284d9c625SLionel Sambuc 
27384d9c625SLionel Sambuc 	for (i = 0; i < __arraycount(x); i++) {
27484d9c625SLionel Sambuc 
27584d9c625SLionel Sambuc 		y = sqrtl(x[i]);
27684d9c625SLionel Sambuc 		z = powl(x[i], 1.0 / 2.0);
27784d9c625SLionel Sambuc 
27884d9c625SLionel Sambuc 		if (fabsl(y - z) > eps)
27984d9c625SLionel Sambuc 			atf_tc_fail_nonfatal("sqrtl(%0.03Lf) != "
28084d9c625SLionel Sambuc 			    "powl(%0.03Lf, 1/2)\n", x[i], x[i]);
28184d9c625SLionel Sambuc 	}
28284d9c625SLionel Sambuc }
28384d9c625SLionel Sambuc 
28484d9c625SLionel Sambuc ATF_TC(sqrtl_inf_neg);
ATF_TC_HEAD(sqrtl_inf_neg,tc)28584d9c625SLionel Sambuc ATF_TC_HEAD(sqrtl_inf_neg, tc)
28684d9c625SLionel Sambuc {
28784d9c625SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtl(-Inf) == NaN");
28884d9c625SLionel Sambuc }
28984d9c625SLionel Sambuc 
ATF_TC_BODY(sqrtl_inf_neg,tc)29084d9c625SLionel Sambuc ATF_TC_BODY(sqrtl_inf_neg, tc)
29184d9c625SLionel Sambuc {
29284d9c625SLionel Sambuc 	const long double x = -1.0L / 0.0L;
29384d9c625SLionel Sambuc 	long double y = sqrtl(x);
29484d9c625SLionel Sambuc 
29584d9c625SLionel Sambuc 	ATF_CHECK(isnan(y) != 0);
29684d9c625SLionel Sambuc }
29784d9c625SLionel Sambuc 
29884d9c625SLionel Sambuc ATF_TC(sqrtl_inf_pos);
ATF_TC_HEAD(sqrtl_inf_pos,tc)29984d9c625SLionel Sambuc ATF_TC_HEAD(sqrtl_inf_pos, tc)
30084d9c625SLionel Sambuc {
30184d9c625SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtl(+Inf) == +Inf");
30284d9c625SLionel Sambuc }
30384d9c625SLionel Sambuc 
ATF_TC_BODY(sqrtl_inf_pos,tc)30484d9c625SLionel Sambuc ATF_TC_BODY(sqrtl_inf_pos, tc)
30584d9c625SLionel Sambuc {
30684d9c625SLionel Sambuc 	const long double x = 1.0L / 0.0L;
30784d9c625SLionel Sambuc 	long double y = sqrtl(x);
30884d9c625SLionel Sambuc 
30984d9c625SLionel Sambuc 	ATF_CHECK(isinf(y) != 0);
31084d9c625SLionel Sambuc 	ATF_CHECK(signbit(y) == 0);
31184d9c625SLionel Sambuc }
31284d9c625SLionel Sambuc 
31384d9c625SLionel Sambuc ATF_TC(sqrtl_zero_neg);
ATF_TC_HEAD(sqrtl_zero_neg,tc)31484d9c625SLionel Sambuc ATF_TC_HEAD(sqrtl_zero_neg, tc)
31584d9c625SLionel Sambuc {
31684d9c625SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtl(-0.0) == -0.0");
31784d9c625SLionel Sambuc }
31884d9c625SLionel Sambuc 
ATF_TC_BODY(sqrtl_zero_neg,tc)31984d9c625SLionel Sambuc ATF_TC_BODY(sqrtl_zero_neg, tc)
32084d9c625SLionel Sambuc {
32184d9c625SLionel Sambuc 	const long double x = -0.0L;
32284d9c625SLionel Sambuc 	long double y = sqrtl(x);
32384d9c625SLionel Sambuc 
32484d9c625SLionel Sambuc 	if (fabsl(y) > 0.0 || signbit(y) == 0)
32584d9c625SLionel Sambuc 		atf_tc_fail_nonfatal("sqrtl(-0.0) != -0.0");
32684d9c625SLionel Sambuc }
32784d9c625SLionel Sambuc 
32884d9c625SLionel Sambuc ATF_TC(sqrtl_zero_pos);
ATF_TC_HEAD(sqrtl_zero_pos,tc)32984d9c625SLionel Sambuc ATF_TC_HEAD(sqrtl_zero_pos, tc)
33084d9c625SLionel Sambuc {
33184d9c625SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "Test sqrtl(+0.0) == +0.0");
33284d9c625SLionel Sambuc }
33384d9c625SLionel Sambuc 
ATF_TC_BODY(sqrtl_zero_pos,tc)33484d9c625SLionel Sambuc ATF_TC_BODY(sqrtl_zero_pos, tc)
33584d9c625SLionel Sambuc {
33684d9c625SLionel Sambuc 	const long double x = 0.0L;
33784d9c625SLionel Sambuc 	long double y = sqrtl(x);
33884d9c625SLionel Sambuc 
33984d9c625SLionel Sambuc 	if (fabsl(y) > 0.0 || signbit(y) != 0)
34084d9c625SLionel Sambuc 		atf_tc_fail_nonfatal("sqrtl(+0.0) != +0.0");
34184d9c625SLionel Sambuc }
34284d9c625SLionel Sambuc 
ATF_TP_ADD_TCS(tp)34311be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
34411be35a1SLionel Sambuc {
34511be35a1SLionel Sambuc 
34611be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrt_nan);
34711be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrt_pow);
34811be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrt_inf_neg);
34911be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrt_inf_pos);
35011be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrt_zero_neg);
35111be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrt_zero_pos);
35211be35a1SLionel Sambuc 
35311be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtf_nan);
35411be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtf_powf);
35511be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtf_inf_neg);
35611be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtf_inf_pos);
35711be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtf_zero_neg);
35811be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtf_zero_pos);
35911be35a1SLionel Sambuc 
36084d9c625SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtl_nan);
36184d9c625SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtl_powl);
36284d9c625SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtl_inf_neg);
36384d9c625SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtl_inf_pos);
36484d9c625SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtl_zero_neg);
36584d9c625SLionel Sambuc 	ATF_TP_ADD_TC(tp, sqrtl_zero_pos);
36684d9c625SLionel Sambuc 
36711be35a1SLionel Sambuc 	return atf_no_error();
36811be35a1SLionel Sambuc }
369