C++ Standard Library C++ STL Library

C++ <complex> - cosh() Function



The C++ <complex> cosh() function returns the complex hyperbolic cosine 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 2𝜋i.

Mathematically, it can be expressed as:

complex cosh

Syntax

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

Parameters

z Specify the complex number.

Return Value

Returns the complex hyperbolic cosine of z.

Example:

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

  return 0;
}

The output of the above code will be:

cosh(z1): (-1.56563,3.29789)
cosh(z2): (3.7622,0)
cosh(z3): (-0.416147,0)

❮ C++ <complex> Library

5