aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richardson <arichardson@FreeBSD.org>2021-02-15 22:06:41 +0000
committerAlex Richardson <arichardson@FreeBSD.org>2021-02-15 22:55:12 +0000
commita7b42c4b7f7ad7bd1b22ab57ed9185bdcea6f0a2 (patch)
tree162f8420bc0ccdaddf3c74f41ea4a7d8a039cb29
parent04e34c0202ea50cea67d5779f54bc612c74e6532 (diff)
downloadsrc-a7b42c4b7f7ad7bd1b22ab57ed9185bdcea6f0a2.tar.gz
src-a7b42c4b7f7ad7bd1b22ab57ed9185bdcea6f0a2.zip
msun: ctanh/ctanhf: Import fix from musl libc
This applies musl commit b02eed9c4841913d690a2d0029737d72615384fe by Szabolcs Nagy and updates the tests accordingly. This also allows removing an XFAIL from the test. musl commit message: complex: fix ctanh(+-0+i*nan) and ctanh(+-0+-i*inf) These cases were incorrect in C11 as described by http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1886.htm PR: 217528 Reviewed By: dim MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D28578
-rw-r--r--lib/msun/src/s_ctanh.c8
-rw-r--r--lib/msun/src/s_ctanhf.c2
-rw-r--r--lib/msun/tests/ctrig_test.c23
3 files changed, 14 insertions, 19 deletions
diff --git a/lib/msun/src/s_ctanh.c b/lib/msun/src/s_ctanh.c
index 13eb9d40b678..93e5ad444501 100644
--- a/lib/msun/src/s_ctanh.c
+++ b/lib/msun/src/s_ctanh.c
@@ -111,11 +111,13 @@ ctanh(double complex z)
}
/*
- * ctanh(x + I NaN) = d(NaN) + I d(NaN)
- * ctanh(x +- I Inf) = dNaN + I dNaN
+ * ctanh(+-0 + i NAN) = +-0 + i NaN
+ * ctanh(+-0 +- i Inf) = +-0 + i NaN
+ * ctanh(x + i NAN) = NaN + i NaN
+ * ctanh(x +- i Inf) = NaN + i NaN
*/
if (!isfinite(y))
- return (CMPLX(y - y, y - y));
+ return (CMPLX(x ? y - y : x, y - y));
/*
* ctanh(+-huge +- I y) ~= +-1 +- I 2sin(2y)/exp(2x), using the
diff --git a/lib/msun/src/s_ctanhf.c b/lib/msun/src/s_ctanhf.c
index 7d375eafd2ae..164a2c23df9e 100644
--- a/lib/msun/src/s_ctanhf.c
+++ b/lib/msun/src/s_ctanhf.c
@@ -61,7 +61,7 @@ ctanhf(float complex z)
}
if (!isfinite(y))
- return (CMPLXF(y - y, y - y));
+ return (CMPLXF(ix ? y - y : x, y - y));
if (ix >= 0x41300000) { /* |x| >= 11 */
float exp_mx = expf(-fabsf(x));
diff --git a/lib/msun/tests/ctrig_test.c b/lib/msun/tests/ctrig_test.c
index 45b2b78b0416..b40373fed29b 100644
--- a/lib/msun/tests/ctrig_test.c
+++ b/lib/msun/tests/ctrig_test.c
@@ -138,13 +138,6 @@ ATF_TC_BODY(test_zero_input, tc)
{
long double complex zero = CMPLXL(0.0, 0.0);
-#if defined(__amd64__)
-#if defined(__clang__) && \
- ((__clang_major__ >= 4))
- atf_tc_expect_fail("test fails with clang 4.x+ - bug 217528");
-#endif
-#endif
-
/* csinh(0) = ctanh(0) = 0; ccosh(0) = 1 (no exceptions raised) */
testall_odd(csinh, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
testall_odd(csin, zero, zero, ALL_STD_EXCEPT, 0, CS_BOTH);
@@ -171,8 +164,8 @@ ATF_TC_BODY(test_nan_inputs, tc)
* NaN,finite NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
* NaN,Inf NaN,NaN [inval] NaN,NaN [inval] NaN,NaN [inval]
* Inf,NaN +-Inf,NaN Inf,NaN 1,+-0
- * 0,NaN +-0,NaN NaN,+-0 NaN,NaN [inval]
- * NaN,0 NaN,0 NaN,+-0 NaN,0
+ * 0,NaN +-0,NaN NaN,+-0 +-0,NaN
+ * NaN,0 NaN,0 NaN,+-0 NaN,+-0
*/
z = nan_nan;
testall_odd(csinh, z, nan_nan, ALL_STD_EXCEPT, 0, 0);
@@ -219,9 +212,9 @@ ATF_TC_BODY(test_nan_inputs, tc)
testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
z = CMPLXL(0, NAN);
- testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, 0);
+ testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
- testall_odd(ctanh, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(ctanh, z, CMPLXL(0, NAN), OPT_INVALID, 0, CS_REAL);
testall_odd(csin, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
testall_odd(ctan, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, 0, CS_REAL);
@@ -232,7 +225,7 @@ ATF_TC_BODY(test_nan_inputs, tc)
testall_odd(ctanh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
testall_odd(csin, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, 0);
- testall_odd(ctan, z, nan_nan, OPT_INVALID, 0, 0);
+ testall_odd(ctan, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, 0, CS_IMAG);
}
ATF_TC(test_inf_inputs);
@@ -252,7 +245,7 @@ ATF_TC_BODY(test_inf_inputs, tc)
* IN CSINH CCOSH CTANH
* Inf,Inf +-Inf,NaN inval +-Inf,NaN inval 1,+-0
* Inf,finite Inf cis(finite) Inf cis(finite) 1,0 sin(2 finite)
- * 0,Inf +-0,NaN inval NaN,+-0 inval NaN,NaN inval
+ * 0,Inf +-0,NaN inval NaN,+-0 inval +-0,NaN
* finite,Inf NaN,NaN inval NaN,NaN inval NaN,NaN inval
*/
z = CMPLXL(INFINITY, INFINITY);
@@ -286,11 +279,11 @@ ATF_TC_BODY(test_inf_inputs, tc)
z = CMPLXL(0, INFINITY);
testall_odd(csinh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
testall_even(ccosh, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
- testall_odd(ctanh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_odd(ctanh, z, CMPLXL(0, NAN), ALL_STD_EXCEPT, FE_INVALID, CS_REAL);
z = CMPLXL(INFINITY, 0);
testall_odd(csin, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
testall_even(ccos, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, 0);
- testall_odd(ctan, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);
+ testall_odd(ctan, z, CMPLXL(NAN, 0), ALL_STD_EXCEPT, FE_INVALID, CS_IMAG);
z = CMPLXL(42, INFINITY);
testall_odd(csinh, z, CMPLXL(NAN, NAN), ALL_STD_EXCEPT, FE_INVALID, 0);