C++ complex proj

The C++ complex proj function compute the projection of the complex number on Riemann sphere.The declaration of the function is shown below.

Link :Wiki Riemann sphere

template<class T> complex<T> proj(const complex<T>& x);
x -The complex number projected on Riemann sphere.

Return type
complex -the value of the projection onto the Riemann sphere.

Some points to note:

i)Any complex ‘x’ will project on ‘x’ itself except for the complex infinities(complex number with infinity as one of it’s part) in which case the real part is projected to infinity.

This function is same as the C <complex.h> header cproj function.

Code example

complex< double > c1( 2.34 , 7.80) ,
c2(23, INFINITY) ; //An instance of complex infinity

cout<< proj( c1 ) << endl
<< proj( c2 );

Output in Code::Blocks ,


The projected value for c2 is (inf,0) ,the ‘inf’ is infinity.

*Side Note

For complex number containing infinite part the proj function,

  INFINITY + i * copysign(0.0, imag(z))

Link :C++ cmath copysign,copysignf and copysignl

Link :C++ complex imag