C++ Standard Library C++ STL Library

C++ <complex> - cos() Function



The C++ <complex> cos() function returns the complex cosine of a complex number z. It is a function on complex plane, and has no branch cuts. Mathematically, it can be expressed as:

complex cos

Syntax

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

Parameters

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

Return Value

Returns the complex cosine of z.

Example:

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

  return 0;
}

The output of the above code will be:

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

❮ C++ <complex> Library

5