summaryrefslogtreecommitdiffstats
path: root/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
diff options
context:
space:
mode:
Diffstat (limited to 'libm/upstream-freebsd/lib/msun/src/s_ctanh.c')
-rw-r--r--libm/upstream-freebsd/lib/msun/src/s_ctanh.c45
1 files changed, 23 insertions, 22 deletions
diff --git a/libm/upstream-freebsd/lib/msun/src/s_ctanh.c b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
index d427e28..e5973c3 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_ctanh.c
@@ -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
*
@@ -64,7 +64,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: head/lib/msun/src/s_ctanh.c 284427 2015-06-15 20:40:44Z tijl $");
#include <complex.h>
#include <math.h>
@@ -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,26 +102,27 @@ ctanh(double complex z)
*/
if (ix >= 0x7ff00000) {
if ((ix & 0xfffff) | lx) /* x is NaN */
- return (cpack(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 (cpack(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))));
+ 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 (cpack(y - y, y - 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 (cpack(copysign(1, x),
+ return (CMPLX(copysign(1, x),
4 * sin(y) * cos(y) * exp_mx * exp_mx));
}
@@ -131,14 +132,14 @@ ctanh(double complex z)
s = sinh(x);
rho = sqrt(1 + s * s); /* = cosh(x) */
denom = 1 + beta * s * s;
- return (cpack((beta * rho * s) / denom, t / denom));
+ return (CMPLX((beta * rho * s) / denom, t / denom));
}
double complex
ctan(double complex z)
{
- /* ctan(z) = -I * ctanh(I * z) */
- z = ctanh(cpack(-cimag(z), creal(z)));
- return (cpack(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)));
}