C++ Standard Library C++ STL Library

C++ <complex> - tanh() Function



The C++ <complex> tanh() function returns the complex hyperbolic 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 imaginary component, with period 𝜋i, and has poles of the first order along the imaginary line, at coordinates (0, 𝜋(1/2 + n)). However no common floating-point representation is able to represent 𝜋/2 exactly.

Mathematically, it can be expressed as:

complex tanh

Syntax

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

Parameters

z Specify the complex number.

Return Value

Returns the complex hyperbolic tangent of z.

Example:

The example below shows the usage of <complex> tanh() 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 hyperbolic tangent
  cout<<"tanh(z1): "<<tanh(z1)<<"\n";
  cout<<"tanh(z2): "<<tanh(z2)<<"\n";
  cout<<"tanh(z3): "<<tanh(z3)<<"\n";

  return 0;
}

The output of the above code will be:

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

❮ C++ <complex> Library

5