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
This commit is contained in:
Alex Richardson 2021-02-15 22:06:41 +00:00
parent 04e34c0202
commit a7b42c4b7f
3 changed files with 14 additions and 19 deletions

View File

@ -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

View File

@ -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));

View File

@ -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);