tan method

Complex tan()

Tangent

Compute the tangent of this complex number.

Implements the formula:

tan(a + bi) = sin(2a)/(cos(2a)+cosh(2b)) + [sinh(2b)/(cos(2a)+cosh(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 (or critical) values in real or imaginary parts of the input may result in infinite or NaN values returned in parts of the result.

Examples:

tan(a ± INFINITY i) = 0 ± i
tan(±INFINITY + bi) = NaN + NaN i
tan(±INFINITY ± INFINITY i) = NaN + NaN i
tan(±π/2 + 0 i) = ±INFINITY + NaN i

Implementation

Complex tan() {
  if (isNaN || real.isInfinite) {
    return Complex.nan;
  }
  if (imaginary > 20.0) {
    return const Cartesian(0.0, 1.0);
  }
  if (imaginary < -20.0) {
    return const Cartesian(0.0, -1.0);
  }

  final real2 = 2.0 * real;
  final imaginary2 = 2.0 * imaginary;
  final d = math.cos(real2) + fastmath.cosh(imaginary2);

  return Cartesian(math.sin(real2) / d, fastmath.sinh(imaginary2) / d);
}