C++ complex cos

The C++ complex ‘cos’ function compute the cosine of the complex number.The declaration of the function is given below.

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

x – A complex number whose cosine is to be computed.

Return type
complex<T> -The complex cosine of ‘x’.

Some points to note:

i) The cosine is computed using the formula.

C++ complex cos

Link : C++ cmath cos

Link : C++ cmath cosh

Code example

complex< double > c1(23 , 45.5);

cout<< cos( c1 ) ;




The computation process of cos( c1 ) function is easy.Simply evaluate the equation,

cos( 23 )*cosh( 45.5 ) – isin( 23 )*sinh( 45.5 )

The complex number obtained is the cosine complex of c1.The cos,sin , cosh and sinh functions are defined under the header <cmath>

Link : C++ cmath sin

Link : C++ cmath sinh

*Side Note

Some cases of cos function,

  ➥cos(conj(z) )=conj( cos(z) )

  ➥cos(±0 + i(±0)) , returns (1 , i0).

  ➥cos(±0 + iNaN) ,returns ((nan , i(±0)).

  ➥cos(±x + i(±∞) ) , returns (-∞ ,i(±∞) ) , for some finite value ‘x’.

  ➥cos(x + iNaN) ,returns NaN + iNaN , for some finite value ‘x’.

  ➥cos(±∞ + iy) ,returns NaN + iNaN , for some finite value ‘y’.

  ➥cos(±∞ + i∞) ,returns (∞ , iNaN)

  ➥cos(±∞ + iNaN) ,returns NaN +iNaN

  ➥cos(NaN + iy) ,returns NaN +iNaN ,for some finite value ‘y’.

  ➥cos(NaN + i(±)∞) ,returns NaN + iNaN .

  ➥cos(NaN + iNaN) ,returns NaN+iNaN.

Link :C++ complex conj