Proj() function for Complex Numbers in C++


This article demonstrate the functioning of proj() in order to perform projection upon complex numbers. Here the syntax of the proj() method in c++ programming as follows;

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

Example

The proj() method takes a parameter as argument which represent the complex number and returns the projection of complex number described below in the sample as;

 Live Demo

#include <iostream>
#include <complex>
using namespace std;
int main(){
   std::complex<double> c1(3, 5);
   cout << "Proj" << c1 << " = " << proj(c1) << endl;
   std::complex<double> c2(0, -INFINITY);
   cout << "Proj" << c2 << " = " << proj(c2) << endl;
   std::complex<double> c3(INFINITY, -1);
   cout << "Proj" << c3 << " = " << proj(c3) << endl;
}

It is mandatory to import the library complex.h in the source to get the definition of the projection method implementation. The above sample yields the following results of the passed the complex number after successful compilation of the above code;

Output

Proj(3,5) = (3,5)
Proj(0,-inf) = (inf,-0)
Proj(inf,1) = (inf,-0)
raja
Published on 16-Jan-2020 12:14:34
Advertisements