git: ce88eb476b86 - main - Fix lib/msun/tests/csqrt_test on platforms with 128-bit long double
Alex Richardson
arichardson at FreeBSD.org
Mon Mar 22 16:58:01 UTC 2021
The branch main has been updated by arichardson:
URL: https://cgit.FreeBSD.org/src/commit/?id=ce88eb476b86cac63cef7466bd71f14b611ab03a
commit ce88eb476b86cac63cef7466bd71f14b611ab03a
Author: Alex Richardson <arichardson at FreeBSD.org>
AuthorDate: 2021-03-22 16:54:02 +0000
Commit: Alex Richardson <arichardson at FreeBSD.org>
CommitDate: 2021-03-22 16:57:43 +0000
Fix lib/msun/tests/csqrt_test on platforms with 128-bit long double
If long double has more than 64 mantissa bits, using uint64_t to hold the
mantissa bits will truncate the value and result in test failures. To fix
this problem use __uint128_t since all platforms that have
__LDBL_MANT_DIG__ > 64 also have compiler support for 128-bit integers.
Reviewed By: rlibby
Differential Revision: https://reviews.freebsd.org/D29076
---
lib/msun/tests/csqrt_test.c | 26 +++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)
diff --git a/lib/msun/tests/csqrt_test.c b/lib/msun/tests/csqrt_test.c
index a46d0ddd45c5..895aec481b60 100644
--- a/lib/msun/tests/csqrt_test.c
+++ b/lib/msun/tests/csqrt_test.c
@@ -257,17 +257,24 @@ test_precision(int maxexp, int mantdig)
{
long double b, x;
long double complex result;
- uint64_t mantbits, sq_mantbits;
+#if LDBL_MANT_DIG <= 64
+ typedef uint64_t ldbl_mant_type;
+#elif LDBL_MANT_DIG <= 128
+ typedef __uint128_t ldbl_mant_type;
+#else
+#error "Unsupported long double format"
+#endif
+ ldbl_mant_type mantbits, sq_mantbits;
int exp, i;
- ATF_CHECK(maxexp > 0 && maxexp % 2 == 0);
- ATF_CHECK(mantdig <= 64);
+ ATF_REQUIRE(maxexp > 0 && maxexp % 2 == 0);
+ ATF_REQUIRE(mantdig <= LDBL_MANT_DIG);
mantdig = rounddown(mantdig, 2);
for (exp = 0; exp <= maxexp; exp += 2) {
- mantbits = ((uint64_t)1 << (mantdig / 2 )) - 1;
- for (i = 0;
- i < 100 && mantbits > ((uint64_t)1 << (mantdig / 2 - 1));
+ mantbits = ((ldbl_mant_type)1 << (mantdig / 2)) - 1;
+ for (i = 0; i < 100 &&
+ mantbits > ((ldbl_mant_type)1 << (mantdig / 2 - 1));
i++, mantbits--) {
sq_mantbits = mantbits * mantbits;
/*
@@ -283,10 +290,10 @@ test_precision(int maxexp, int mantdig)
b = ldexpl((long double)sq_mantbits,
exp - 1 - mantdig);
x = ldexpl(mantbits, (exp - 2 - mantdig) / 2);
- ATF_CHECK_EQ(b, x * x * 2);
+ CHECK_FPEQUAL(b, x * x * 2);
result = t_csqrt(CMPLXL(0, b));
- ATF_CHECK_EQ(x, creall(result));
- ATF_CHECK_EQ(x, cimagl(result));
+ CHECK_FPEQUAL(x, creall(result));
+ CHECK_FPEQUAL(x, cimagl(result));
}
}
}
@@ -345,6 +352,7 @@ ATF_TC_BODY(csqrtl, tc)
test_overflow(LDBL_MAX_EXP);
+ /* i386 is configured to use 53-bit rounding precision for long double. */
test_precision(LDBL_MAX_EXP,
#ifndef __i386__
LDBL_MANT_DIG
More information about the dev-commits-src-main
mailing list