- Change comments to be more consistent with s_ccosh.c and s_csinh.c.
- Fix a case where NaNs were not mixed correctly and signalling NaNs were not converted to quiet NaNs. - Eliminate two negations from ctan(z). In collaboration with: bde
This commit is contained in:
parent
f0f050e0f9
commit
68b433d790
@ -25,7 +25,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Hyperbolic tangent of a complex argument z = x + i y.
|
||||
* Hyperbolic tangent of a complex argument z = x + I y.
|
||||
*
|
||||
* The algorithm is from:
|
||||
*
|
||||
@ -44,15 +44,15 @@
|
||||
*
|
||||
* tanh(z) = sinh(z) / cosh(z)
|
||||
*
|
||||
* sinh(x) cos(y) + i cosh(x) sin(y)
|
||||
* sinh(x) cos(y) + I cosh(x) sin(y)
|
||||
* = ---------------------------------
|
||||
* cosh(x) cos(y) + i sinh(x) sin(y)
|
||||
* cosh(x) cos(y) + I sinh(x) sin(y)
|
||||
*
|
||||
* cosh(x) sinh(x) / cos^2(y) + i tan(y)
|
||||
* cosh(x) sinh(x) / cos^2(y) + I tan(y)
|
||||
* = -------------------------------------
|
||||
* 1 + sinh^2(x) / cos^2(y)
|
||||
*
|
||||
* beta rho s + i t
|
||||
* beta rho s + I t
|
||||
* = ----------------
|
||||
* 1 + beta s^2
|
||||
*
|
||||
@ -85,16 +85,16 @@ ctanh(double complex z)
|
||||
ix = hx & 0x7fffffff;
|
||||
|
||||
/*
|
||||
* ctanh(NaN + i 0) = NaN + i 0
|
||||
* ctanh(NaN +- I 0) = d(NaN) +- I 0
|
||||
*
|
||||
* ctanh(NaN + i y) = NaN + i NaN for y != 0
|
||||
* ctanh(NaN + I y) = d(NaN,y) + I d(NaN,y) for y != 0
|
||||
*
|
||||
* The imaginary part has the sign of x*sin(2*y), but there's no
|
||||
* special effort to get this right.
|
||||
*
|
||||
* ctanh(+-Inf +- i Inf) = +-1 +- 0
|
||||
* ctanh(+-Inf +- I Inf) = +-1 +- I 0
|
||||
*
|
||||
* ctanh(+-Inf + i y) = +-1 + 0 sin(2y) for y finite
|
||||
* ctanh(+-Inf + I y) = +-1 + I 0 sin(2y) for y finite
|
||||
*
|
||||
* The imaginary part of the sign is unspecified. This special
|
||||
* case is only needed to avoid a spurious invalid exception when
|
||||
@ -102,24 +102,25 @@ ctanh(double complex z)
|
||||
*/
|
||||
if (ix >= 0x7ff00000) {
|
||||
if ((ix & 0xfffff) | lx) /* x is NaN */
|
||||
return (CMPLX(x, (y == 0 ? y : x * y)));
|
||||
return (CMPLX((x + 0) * (y + 0),
|
||||
y == 0 ? y : (x + 0) * (y + 0)));
|
||||
SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */
|
||||
return (CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
|
||||
}
|
||||
|
||||
/*
|
||||
* ctanh(x + i NAN) = NaN + i NaN
|
||||
* ctanh(x +- i Inf) = NaN + i NaN
|
||||
* ctanh(x + I NaN) = d(NaN) + I d(NaN)
|
||||
* ctanh(x +- I Inf) = dNaN + I dNaN
|
||||
*/
|
||||
if (!isfinite(y))
|
||||
return (CMPLX(y - y, y - y));
|
||||
|
||||
/*
|
||||
* ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the
|
||||
* ctanh(+-huge +- I y) ~= +-1 +- I 2sin(2y)/exp(2x), using the
|
||||
* approximation sinh^2(huge) ~= exp(2*huge) / 4.
|
||||
* We use a modified formula to avoid spurious overflow.
|
||||
*/
|
||||
if (ix >= 0x40360000) { /* x >= 22 */
|
||||
if (ix >= 0x40360000) { /* |x| >= 22 */
|
||||
double exp_mx = exp(-fabs(x));
|
||||
return (CMPLX(copysign(1, x),
|
||||
4 * sin(y) * cos(y) * exp_mx * exp_mx));
|
||||
@ -138,7 +139,7 @@ double complex
|
||||
ctan(double complex z)
|
||||
{
|
||||
|
||||
/* ctan(z) = -I * ctanh(I * z) */
|
||||
z = ctanh(CMPLX(-cimag(z), creal(z)));
|
||||
return (CMPLX(cimag(z), -creal(z)));
|
||||
/* ctan(z) = -I * ctanh(I * z) = I * conj(ctanh(I * conj(z))) */
|
||||
z = ctanh(CMPLX(cimag(z), creal(z)));
|
||||
return (CMPLX(cimag(z), creal(z)));
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ ctanhf(float complex z)
|
||||
if (!isfinite(y))
|
||||
return (CMPLXF(y - y, y - y));
|
||||
|
||||
if (ix >= 0x41300000) { /* x >= 11 */
|
||||
if (ix >= 0x41300000) { /* |x| >= 11 */
|
||||
float exp_mx = expf(-fabsf(x));
|
||||
return (CMPLXF(copysignf(1, x),
|
||||
4 * sinf(y) * cosf(y) * exp_mx * exp_mx));
|
||||
@ -78,7 +78,7 @@ float complex
|
||||
ctanf(float complex z)
|
||||
{
|
||||
|
||||
z = ctanhf(CMPLXF(-cimagf(z), crealf(z)));
|
||||
return (CMPLXF(cimagf(z), -crealf(z)));
|
||||
z = ctanhf(CMPLXF(cimagf(z), crealf(z)));
|
||||
return (CMPLXF(cimagf(z), crealf(z)));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user