xref: /freebsd/lib/msun/tests/csqrt_test.c (revision a2f733abcff64628b7771a47089628b7327a88bd)
14dc607e7SEnji Cooper /*-
24dc607e7SEnji Cooper  * Copyright (c) 2007 David Schultz <das@FreeBSD.org>
34dc607e7SEnji Cooper  * All rights reserved.
44dc607e7SEnji Cooper  *
54dc607e7SEnji Cooper  * Redistribution and use in source and binary forms, with or without
64dc607e7SEnji Cooper  * modification, are permitted provided that the following conditions
74dc607e7SEnji Cooper  * are met:
84dc607e7SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
94dc607e7SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
104dc607e7SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
114dc607e7SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
124dc607e7SEnji Cooper  *    documentation and/or other materials provided with the distribution.
134dc607e7SEnji Cooper  *
144dc607e7SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
154dc607e7SEnji Cooper  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164dc607e7SEnji Cooper  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174dc607e7SEnji Cooper  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184dc607e7SEnji Cooper  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194dc607e7SEnji Cooper  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204dc607e7SEnji Cooper  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214dc607e7SEnji Cooper  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224dc607e7SEnji Cooper  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234dc607e7SEnji Cooper  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244dc607e7SEnji Cooper  * SUCH DAMAGE.
254dc607e7SEnji Cooper  */
264dc607e7SEnji Cooper 
274dc607e7SEnji Cooper /*
284dc607e7SEnji Cooper  * Tests for csqrt{,f}()
294dc607e7SEnji Cooper  */
304dc607e7SEnji Cooper 
314dc607e7SEnji Cooper #include <sys/param.h>
324dc607e7SEnji Cooper 
334dc607e7SEnji Cooper #include <complex.h>
344dc607e7SEnji Cooper #include <float.h>
354dc607e7SEnji Cooper #include <math.h>
364dc607e7SEnji Cooper #include <stdio.h>
374dc607e7SEnji Cooper 
384dc607e7SEnji Cooper #include "test-utils.h"
394dc607e7SEnji Cooper 
404dc607e7SEnji Cooper /*
414dc607e7SEnji Cooper  * This is a test hook that can point to csqrtl(), _csqrt(), or to _csqrtf().
424dc607e7SEnji Cooper  * The latter two convert to float or double, respectively, and test csqrtf()
434dc607e7SEnji Cooper  * and csqrt() with the same arguments.
444dc607e7SEnji Cooper  */
45abe427afSEnji Cooper static long double complex (*t_csqrt)(long double complex);
464dc607e7SEnji Cooper 
474dc607e7SEnji Cooper static long double complex
_csqrtf(long double complex d)484dc607e7SEnji Cooper _csqrtf(long double complex d)
494dc607e7SEnji Cooper {
504dc607e7SEnji Cooper 
514dc607e7SEnji Cooper 	return (csqrtf((float complex)d));
524dc607e7SEnji Cooper }
534dc607e7SEnji Cooper 
544dc607e7SEnji Cooper static long double complex
_csqrt(long double complex d)554dc607e7SEnji Cooper _csqrt(long double complex d)
564dc607e7SEnji Cooper {
574dc607e7SEnji Cooper 
584dc607e7SEnji Cooper 	return (csqrt((double complex)d));
594dc607e7SEnji Cooper }
604dc607e7SEnji Cooper 
614dc607e7SEnji Cooper #pragma	STDC CX_LIMITED_RANGE	OFF
624dc607e7SEnji Cooper 
634dc607e7SEnji Cooper /*
644dc607e7SEnji Cooper  * Compare d1 and d2 using special rules: NaN == NaN and +0 != -0.
654dc607e7SEnji Cooper  * Fail an assertion if they differ.
664dc607e7SEnji Cooper  */
67b424e003SAlex Richardson #define assert_equal(d1, d2) CHECK_CFPEQUAL_CS(d1, d2, CS_BOTH)
684dc607e7SEnji Cooper 
694dc607e7SEnji Cooper /*
704dc607e7SEnji Cooper  * Test csqrt for some finite arguments where the answer is exact.
714dc607e7SEnji Cooper  * (We do not test if it produces correctly rounded answers when the
724dc607e7SEnji Cooper  * result is inexact, nor do we check whether it throws spurious
734dc607e7SEnji Cooper  * exceptions.)
744dc607e7SEnji Cooper  */
754dc607e7SEnji Cooper static void
test_finite(void)76abe427afSEnji Cooper test_finite(void)
774dc607e7SEnji Cooper {
784dc607e7SEnji Cooper 	static const double tests[] = {
794dc607e7SEnji Cooper 	     /* csqrt(a + bI) = x + yI */
804dc607e7SEnji Cooper 	     /* a	b	x	y */
814dc607e7SEnji Cooper 		0,	8,	2,	2,
824dc607e7SEnji Cooper 		0,	-8,	2,	-2,
834dc607e7SEnji Cooper 		4,	0,	2,	0,
844dc607e7SEnji Cooper 		-4,	0,	0,	2,
854dc607e7SEnji Cooper 		3,	4,	2,	1,
864dc607e7SEnji Cooper 		3,	-4,	2,	-1,
874dc607e7SEnji Cooper 		-3,	4,	1,	2,
884dc607e7SEnji Cooper 		-3,	-4,	1,	-2,
894dc607e7SEnji Cooper 		5,	12,	3,	2,
904dc607e7SEnji Cooper 		7,	24,	4,	3,
914dc607e7SEnji Cooper 		9,	40,	5,	4,
924dc607e7SEnji Cooper 		11,	60,	6,	5,
934dc607e7SEnji Cooper 		13,	84,	7,	6,
944dc607e7SEnji Cooper 		33,	56,	7,	4,
954dc607e7SEnji Cooper 		39,	80,	8,	5,
964dc607e7SEnji Cooper 		65,	72,	9,	4,
974dc607e7SEnji Cooper 		987,	9916,	74,	67,
984dc607e7SEnji Cooper 		5289,	6640,	83,	40,
994dc607e7SEnji Cooper 		460766389075.0, 16762287900.0, 678910, 12345
1004dc607e7SEnji Cooper 	};
1014dc607e7SEnji Cooper 	/*
1024dc607e7SEnji Cooper 	 * We also test some multiples of the above arguments. This
1034dc607e7SEnji Cooper 	 * array defines which multiples we use. Note that these have
1044dc607e7SEnji Cooper 	 * to be small enough to not cause overflow for float precision
1054dc607e7SEnji Cooper 	 * with all of the constants in the above table.
1064dc607e7SEnji Cooper 	 */
1074dc607e7SEnji Cooper 	static const double mults[] = {
1084dc607e7SEnji Cooper 		1,
1094dc607e7SEnji Cooper 		2,
1104dc607e7SEnji Cooper 		3,
1114dc607e7SEnji Cooper 		13,
1124dc607e7SEnji Cooper 		16,
1134dc607e7SEnji Cooper 		0x1.p30,
1144dc607e7SEnji Cooper 		0x1.p-30,
1154dc607e7SEnji Cooper 	};
1164dc607e7SEnji Cooper 
1174dc607e7SEnji Cooper 	double a, b;
1184dc607e7SEnji Cooper 	double x, y;
119abe427afSEnji Cooper 	unsigned i, j;
1204dc607e7SEnji Cooper 
1214dc607e7SEnji Cooper 	for (i = 0; i < nitems(tests); i += 4) {
1224dc607e7SEnji Cooper 		for (j = 0; j < nitems(mults); j++) {
1234dc607e7SEnji Cooper 			a = tests[i] * mults[j] * mults[j];
1244dc607e7SEnji Cooper 			b = tests[i + 1] * mults[j] * mults[j];
1254dc607e7SEnji Cooper 			x = tests[i + 2] * mults[j];
1264dc607e7SEnji Cooper 			y = tests[i + 3] * mults[j];
127133bc645SAlex Richardson 			ATF_CHECK(t_csqrt(CMPLXL(a, b)) == CMPLXL(x, y));
1284dc607e7SEnji Cooper 		}
1294dc607e7SEnji Cooper 	}
1304dc607e7SEnji Cooper 
1314dc607e7SEnji Cooper }
1324dc607e7SEnji Cooper 
1334dc607e7SEnji Cooper /*
1344dc607e7SEnji Cooper  * Test the handling of +/- 0.
1354dc607e7SEnji Cooper  */
1364dc607e7SEnji Cooper static void
test_zeros(void)137abe427afSEnji Cooper test_zeros(void)
1384dc607e7SEnji Cooper {
1394dc607e7SEnji Cooper 
1404dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(0.0, 0.0)), CMPLXL(0.0, 0.0));
1414dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(-0.0, 0.0)), CMPLXL(0.0, 0.0));
1424dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(0.0, -0.0)), CMPLXL(0.0, -0.0));
1434dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(-0.0, -0.0)), CMPLXL(0.0, -0.0));
1444dc607e7SEnji Cooper }
1454dc607e7SEnji Cooper 
1464dc607e7SEnji Cooper /*
1474dc607e7SEnji Cooper  * Test the handling of infinities when the other argument is not NaN.
1484dc607e7SEnji Cooper  */
1494dc607e7SEnji Cooper static void
test_infinities(void)150abe427afSEnji Cooper test_infinities(void)
1514dc607e7SEnji Cooper {
1524dc607e7SEnji Cooper 	static const double vals[] = {
1534dc607e7SEnji Cooper 		0.0,
1544dc607e7SEnji Cooper 		-0.0,
1554dc607e7SEnji Cooper 		42.0,
1564dc607e7SEnji Cooper 		-42.0,
1574dc607e7SEnji Cooper 		INFINITY,
1584dc607e7SEnji Cooper 		-INFINITY,
1594dc607e7SEnji Cooper 	};
1604dc607e7SEnji Cooper 
161abe427afSEnji Cooper 	unsigned i;
1624dc607e7SEnji Cooper 
1634dc607e7SEnji Cooper 	for (i = 0; i < nitems(vals); i++) {
1644dc607e7SEnji Cooper 		if (isfinite(vals[i])) {
1654dc607e7SEnji Cooper 			assert_equal(t_csqrt(CMPLXL(-INFINITY, vals[i])),
1664dc607e7SEnji Cooper 			    CMPLXL(0.0, copysignl(INFINITY, vals[i])));
1674dc607e7SEnji Cooper 			assert_equal(t_csqrt(CMPLXL(INFINITY, vals[i])),
1684dc607e7SEnji Cooper 			    CMPLXL(INFINITY, copysignl(0.0, vals[i])));
1694dc607e7SEnji Cooper 		}
1704dc607e7SEnji Cooper 		assert_equal(t_csqrt(CMPLXL(vals[i], INFINITY)),
1714dc607e7SEnji Cooper 		    CMPLXL(INFINITY, INFINITY));
1724dc607e7SEnji Cooper 		assert_equal(t_csqrt(CMPLXL(vals[i], -INFINITY)),
1734dc607e7SEnji Cooper 		    CMPLXL(INFINITY, -INFINITY));
1744dc607e7SEnji Cooper 	}
1754dc607e7SEnji Cooper }
1764dc607e7SEnji Cooper 
1774dc607e7SEnji Cooper /*
1784dc607e7SEnji Cooper  * Test the handling of NaNs.
1794dc607e7SEnji Cooper  */
1804dc607e7SEnji Cooper static void
test_nans(void)181abe427afSEnji Cooper test_nans(void)
1824dc607e7SEnji Cooper {
1834dc607e7SEnji Cooper 
184133bc645SAlex Richardson 	ATF_CHECK(creall(t_csqrt(CMPLXL(INFINITY, NAN))) == INFINITY);
185133bc645SAlex Richardson 	ATF_CHECK(isnan(cimagl(t_csqrt(CMPLXL(INFINITY, NAN)))));
1864dc607e7SEnji Cooper 
187133bc645SAlex Richardson 	ATF_CHECK(isnan(creall(t_csqrt(CMPLXL(-INFINITY, NAN)))));
188133bc645SAlex Richardson 	ATF_CHECK(isinf(cimagl(t_csqrt(CMPLXL(-INFINITY, NAN)))));
1894dc607e7SEnji Cooper 
1904dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, INFINITY)),
1914dc607e7SEnji Cooper 		     CMPLXL(INFINITY, INFINITY));
1924dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, -INFINITY)),
1934dc607e7SEnji Cooper 		     CMPLXL(INFINITY, -INFINITY));
1944dc607e7SEnji Cooper 
1954dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(0.0, NAN)), CMPLXL(NAN, NAN));
1964dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(-0.0, NAN)), CMPLXL(NAN, NAN));
1974dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(42.0, NAN)), CMPLXL(NAN, NAN));
1984dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(-42.0, NAN)), CMPLXL(NAN, NAN));
1994dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, 0.0)), CMPLXL(NAN, NAN));
2004dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, -0.0)), CMPLXL(NAN, NAN));
2014dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, 42.0)), CMPLXL(NAN, NAN));
2024dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, -42.0)), CMPLXL(NAN, NAN));
2034dc607e7SEnji Cooper 	assert_equal(t_csqrt(CMPLXL(NAN, NAN)), CMPLXL(NAN, NAN));
2044dc607e7SEnji Cooper }
2054dc607e7SEnji Cooper 
2064dc607e7SEnji Cooper /*
2074dc607e7SEnji Cooper  * Test whether csqrt(a + bi) works for inputs that are large enough to
208fca37d47SRyan Libby  * cause overflow in hypot(a, b) + a.  Each of the tests is scaled up to
209fca37d47SRyan Libby  * near MAX_EXP.
2104dc607e7SEnji Cooper  */
2114dc607e7SEnji Cooper static void
test_overflow(int maxexp)2124dc607e7SEnji Cooper test_overflow(int maxexp)
2134dc607e7SEnji Cooper {
2144dc607e7SEnji Cooper 	long double a, b;
2154dc607e7SEnji Cooper 	long double complex result;
216fca37d47SRyan Libby 	int exp, i;
2174dc607e7SEnji Cooper 
218133bc645SAlex Richardson 	ATF_CHECK(maxexp > 0 && maxexp % 2 == 0);
219fca37d47SRyan Libby 
220fca37d47SRyan Libby 	for (i = 0; i < 4; i++) {
221fca37d47SRyan Libby 		exp = maxexp - 2 * i;
222fca37d47SRyan Libby 
223fca37d47SRyan Libby 		/* csqrt(115 + 252*I) == 14 + 9*I */
224fca37d47SRyan Libby 		a = ldexpl(115 * 0x1p-8, exp);
225fca37d47SRyan Libby 		b = ldexpl(252 * 0x1p-8, exp);
2264dc607e7SEnji Cooper 		result = t_csqrt(CMPLXL(a, b));
227133bc645SAlex Richardson 		ATF_CHECK_EQ(creall(result), ldexpl(14 * 0x1p-4, exp / 2));
228133bc645SAlex Richardson 		ATF_CHECK_EQ(cimagl(result), ldexpl(9 * 0x1p-4, exp / 2));
229fca37d47SRyan Libby 
230fca37d47SRyan Libby 		/* csqrt(-11 + 60*I) = 5 + 6*I */
231fca37d47SRyan Libby 		a = ldexpl(-11 * 0x1p-6, exp);
232fca37d47SRyan Libby 		b = ldexpl(60 * 0x1p-6, exp);
233fca37d47SRyan Libby 		result = t_csqrt(CMPLXL(a, b));
234133bc645SAlex Richardson 		ATF_CHECK_EQ(creall(result), ldexpl(5 * 0x1p-3, exp / 2));
235133bc645SAlex Richardson 		ATF_CHECK_EQ(cimagl(result), ldexpl(6 * 0x1p-3, exp / 2));
236fca37d47SRyan Libby 
237fca37d47SRyan Libby 		/* csqrt(225 + 0*I) == 15 + 0*I */
238fca37d47SRyan Libby 		a = ldexpl(225 * 0x1p-8, exp);
239fca37d47SRyan Libby 		b = 0;
240fca37d47SRyan Libby 		result = t_csqrt(CMPLXL(a, b));
241133bc645SAlex Richardson 		ATF_CHECK_EQ(creall(result), ldexpl(15 * 0x1p-4, exp / 2));
242133bc645SAlex Richardson 		ATF_CHECK_EQ(cimagl(result), 0);
243fca37d47SRyan Libby 	}
244fca37d47SRyan Libby }
245fca37d47SRyan Libby 
246fca37d47SRyan Libby /*
247fca37d47SRyan Libby  * Test that precision is maintained for some large squares.  Set all or
248fca37d47SRyan Libby  * some bits in the lower mantdig/2 bits, square the number, and try to
249fca37d47SRyan Libby  * recover the sqrt.  Note:
250fca37d47SRyan Libby  * 	(x + xI)**2 = 2xxI
251fca37d47SRyan Libby  */
252fca37d47SRyan Libby static void
test_precision(int maxexp,int mantdig)253fca37d47SRyan Libby test_precision(int maxexp, int mantdig)
254fca37d47SRyan Libby {
255fca37d47SRyan Libby 	long double b, x;
256fca37d47SRyan Libby 	long double complex result;
257*ce88eb47SAlex Richardson #if LDBL_MANT_DIG <= 64
258*ce88eb47SAlex Richardson 	typedef uint64_t ldbl_mant_type;
259*ce88eb47SAlex Richardson #elif LDBL_MANT_DIG <= 128
260*ce88eb47SAlex Richardson 	typedef __uint128_t ldbl_mant_type;
261*ce88eb47SAlex Richardson #else
262*ce88eb47SAlex Richardson #error "Unsupported long double format"
263*ce88eb47SAlex Richardson #endif
264*ce88eb47SAlex Richardson 	ldbl_mant_type mantbits, sq_mantbits;
265fca37d47SRyan Libby 	int exp, i;
266fca37d47SRyan Libby 
267*ce88eb47SAlex Richardson 	ATF_REQUIRE(maxexp > 0 && maxexp % 2 == 0);
268*ce88eb47SAlex Richardson 	ATF_REQUIRE(mantdig <= LDBL_MANT_DIG);
269fca37d47SRyan Libby 	mantdig = rounddown(mantdig, 2);
270fca37d47SRyan Libby 
271fca37d47SRyan Libby 	for (exp = 0; exp <= maxexp; exp += 2) {
272*ce88eb47SAlex Richardson 		mantbits = ((ldbl_mant_type)1 << (mantdig / 2)) - 1;
273*ce88eb47SAlex Richardson 		for (i = 0; i < 100 &&
274*ce88eb47SAlex Richardson 		     mantbits > ((ldbl_mant_type)1 << (mantdig / 2 - 1));
275fca37d47SRyan Libby 		     i++, mantbits--) {
276fca37d47SRyan Libby 			sq_mantbits = mantbits * mantbits;
277fca37d47SRyan Libby 			/*
278fca37d47SRyan Libby 			 * sq_mantibts is a mantdig-bit number.  Divide by
279fca37d47SRyan Libby 			 * 2**mantdig to normalize it to [0.5, 1), where,
280fca37d47SRyan Libby 			 * note, the binary power will be -1.  Raise it by
281fca37d47SRyan Libby 			 * 2**exp for the test.  exp is even.  Lower it by
282fca37d47SRyan Libby 			 * one to reach a final binary power which is also
283fca37d47SRyan Libby 			 * even.  The result should be exactly
284fca37d47SRyan Libby 			 * representable, given that mantdig is less than or
285fca37d47SRyan Libby 			 * equal to the available precision.
286fca37d47SRyan Libby 			 */
287fca37d47SRyan Libby 			b = ldexpl((long double)sq_mantbits,
288fca37d47SRyan Libby 			    exp - 1 - mantdig);
289fca37d47SRyan Libby 			x = ldexpl(mantbits, (exp - 2 - mantdig) / 2);
290*ce88eb47SAlex Richardson 			CHECK_FPEQUAL(b, x * x * 2);
291fca37d47SRyan Libby 			result = t_csqrt(CMPLXL(0, b));
292*ce88eb47SAlex Richardson 			CHECK_FPEQUAL(x, creall(result));
293*ce88eb47SAlex Richardson 			CHECK_FPEQUAL(x, cimagl(result));
294fca37d47SRyan Libby 		}
295fca37d47SRyan Libby 	}
2964dc607e7SEnji Cooper }
2974dc607e7SEnji Cooper 
298133bc645SAlex Richardson ATF_TC_WITHOUT_HEAD(csqrt);
ATF_TC_BODY(csqrt,tc)299133bc645SAlex Richardson ATF_TC_BODY(csqrt, tc)
3004dc607e7SEnji Cooper {
3014dc607e7SEnji Cooper 	/* Test csqrt() */
3024dc607e7SEnji Cooper 	t_csqrt = _csqrt;
3034dc607e7SEnji Cooper 
3044dc607e7SEnji Cooper 	test_finite();
3054dc607e7SEnji Cooper 
3064dc607e7SEnji Cooper 	test_zeros();
3074dc607e7SEnji Cooper 
3084dc607e7SEnji Cooper 	test_infinities();
3094dc607e7SEnji Cooper 
3104dc607e7SEnji Cooper 	test_nans();
3114dc607e7SEnji Cooper 
3124dc607e7SEnji Cooper 	test_overflow(DBL_MAX_EXP);
3134dc607e7SEnji Cooper 
314fca37d47SRyan Libby 	test_precision(DBL_MAX_EXP, DBL_MANT_DIG);
315133bc645SAlex Richardson }
316fca37d47SRyan Libby 
317133bc645SAlex Richardson ATF_TC_WITHOUT_HEAD(csqrtf);
ATF_TC_BODY(csqrtf,tc)318133bc645SAlex Richardson ATF_TC_BODY(csqrtf, tc)
319133bc645SAlex Richardson {
3204dc607e7SEnji Cooper 	/* Now test csqrtf() */
3214dc607e7SEnji Cooper 	t_csqrt = _csqrtf;
3224dc607e7SEnji Cooper 
3234dc607e7SEnji Cooper 	test_finite();
3244dc607e7SEnji Cooper 
325fca37d47SRyan Libby 	test_zeros();
3264dc607e7SEnji Cooper 
327fca37d47SRyan Libby 	test_infinities();
3284dc607e7SEnji Cooper 
329fca37d47SRyan Libby 	test_nans();
3304dc607e7SEnji Cooper 
331fca37d47SRyan Libby 	test_overflow(FLT_MAX_EXP);
332fca37d47SRyan Libby 
333fca37d47SRyan Libby 	test_precision(FLT_MAX_EXP, FLT_MANT_DIG);
334133bc645SAlex Richardson }
335fca37d47SRyan Libby 
336133bc645SAlex Richardson ATF_TC_WITHOUT_HEAD(csqrtl);
ATF_TC_BODY(csqrtl,tc)337133bc645SAlex Richardson ATF_TC_BODY(csqrtl, tc)
338133bc645SAlex Richardson {
3394dc607e7SEnji Cooper 	/* Now test csqrtl() */
3404dc607e7SEnji Cooper 	t_csqrt = csqrtl;
3414dc607e7SEnji Cooper 
3424dc607e7SEnji Cooper 	test_finite();
3434dc607e7SEnji Cooper 
344fca37d47SRyan Libby 	test_zeros();
3454dc607e7SEnji Cooper 
346fca37d47SRyan Libby 	test_infinities();
3474dc607e7SEnji Cooper 
348fca37d47SRyan Libby 	test_nans();
349fca37d47SRyan Libby 
350fca37d47SRyan Libby 	test_overflow(LDBL_MAX_EXP);
351fca37d47SRyan Libby 
352*ce88eb47SAlex Richardson 	/* i386 is configured to use 53-bit rounding precision for long double. */
353fca37d47SRyan Libby 	test_precision(LDBL_MAX_EXP,
354fca37d47SRyan Libby #ifndef __i386__
355fca37d47SRyan Libby 	    LDBL_MANT_DIG
356fca37d47SRyan Libby #else
357fca37d47SRyan Libby 	    DBL_MANT_DIG
358fca37d47SRyan Libby #endif
359fca37d47SRyan Libby 	    );
360133bc645SAlex Richardson }
361fca37d47SRyan Libby 
ATF_TP_ADD_TCS(tp)362133bc645SAlex Richardson ATF_TP_ADD_TCS(tp)
363133bc645SAlex Richardson {
364133bc645SAlex Richardson 	ATF_TP_ADD_TC(tp, csqrt);
365133bc645SAlex Richardson 	ATF_TP_ADD_TC(tp, csqrtf);
366133bc645SAlex Richardson 	ATF_TP_ADD_TC(tp, csqrtl);
367133bc645SAlex Richardson 
368133bc645SAlex Richardson 	return (atf_no_error());
3694dc607e7SEnji Cooper }
370