C++ Standard Library C++ STL Library

C++ <complex> - tan() Function



The C++ <complex> tan() function returns the complex tangent of a complex number z. It is a function on complex plane, and has no branch cuts. It is periodic with respect to the real component, with period 𝜋i, and has poles of the first order along the real line, at coordinates (𝜋(1/2 + n), 0). However no common floating-point representation is able to represent 𝜋/2 exactly.

Mathematically, it can be expressed as:

complex tan

Syntax

template<class T> complex<T> tan (const complex<T>& z);

Parameters

z Specify the complex number, representing an angle expressed in radians.

Return Value

Returns the complex tangent of z.

Example:

The example below shows the usage of <complex> tan() function.

#include <iostream>
#include <complex>
using namespace std;
 
int main (){
  complex<double> z1 (2, 2);
  complex<double> z2 (2, 0);
  complex<double> z3 (0, 2);

  //calculate the complex tangent
  cout<<"tan(z1): "<<tan(z1)<<"\n";
  cout<<"tan(z2): "<<tan(z2)<<"\n";
  cout<<"tan(z3): "<<tan(z3)<<"\n";

  return 0;
}

The output of the above code will be:

tan(z1): (-0.028393,1.02384)
tan(z2): (-2.18504,0)
tan(z3): (0,0.964028)

❮ C++ <complex> Library