tanh method
Hyperbolic tangent
Compute the hyperbolic tangent of this complex number.
Implements the formula:
tan(a + bi) = sinh(2a)/(cosh(2a)+cos(2b)) + [sin(2b)/(cosh(2a)+cos(2b))]i
where the (real) functions on the right-hand side are math.sin, math.cos, fastmath.cosh and fastmath.sinh.
Returns nan
if either real or imaginary part of the
input argument is NaN
.
Infinite values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.
Examples:
tanh(a ± INFINITY i) = NaN + NaN i
tanh(±INFINITY + bi) = ±1 + 0 i
tanh(±INFINITY ± INFINITY i) = NaN + NaN i
tanh(0 + (π/2)i) = NaN + INFINITY i
Implementation
Complex tanh() {
if (isNaN || imaginary.isInfinite) {
return Complex.nan;
}
if (real > 20.0) {
return const Cartesian(1.0, 0.0);
}
if (real < -20.0) {
return const Cartesian(-1.0, 0.0);
}
final real2 = 2.0 * real;
final imaginary2 = 2.0 * imaginary;
final d = fastmath.cosh(real2) + math.cos(imaginary2);
return Cartesian(fastmath.sinh(real2) / d, math.sin(imaginary2) / d);
}