C++ Standard Library C++ STL Library

C++ <complex> - conj() Function



The C++ <complex> conj() function returns the complex conjugate of a complex number. The conjugate of a complex number (real, imag) is (real, -imag).

The additional overloads is added in C++11 to provide the arguments of any fundamental arithmetic type. In this case, the function assumes the value has a zero imaginary component, and thus simply returns z converted to the proper type.

Syntax

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

//additional overloads
double conj (ArithmeticType z);

Parameters

z Specify a complex value.

Return Value

Returns complex conjugate of the complex number.

Example:

The example below shows the usage of <complex> conj() 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);

  //calculating complex conjugate 
  cout<<"conj(z1): "<<conj(z1)<<"\n";
  cout<<"conj(z2): "<<conj(z2)<<"\n";
  cout<<"conj(z3): "<<conj(z3)<<"\n";

  return 0;
}

The output of the above code will be:

conj(z1): (2,-2)
conj(z2): (2,-0)
conj(z3): (0,-2)

❮ C++ <complex> Library

5