C++ <complex> - proj() Function

The C++ <complex> proj() function returns the projection of a complex number onto the Riemann sphere. For most z, proj(z) == z, except for complex infinities, which are mapped to (INFINITY, 0) or (INFINITY, -0). The sign of the imaginary (zero) component is the sign of imag(z).

The additional overloads is added 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 proj (const complex<T>& z);

//additional overloads
double proj (ArithmeticType z);
```

Parameters

 `z` Specify a complex value.

Return Value

Returns projection of the complex number onto the Riemann sphere.

Example:

The example below shows the usage of <complex> proj() 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 projection of the complex
//number onto the Riemann sphere
cout<<"proj(z1): "<<proj(z1)<<"\n";
cout<<"proj(z2): "<<proj(z2)<<"\n";
cout<<"proj(z3): "<<proj(z3)<<"\n";

return 0;
}
```

The output of the above code will be:

```proj(z1): (2,2)
proj(z2): (2,0)
proj(z3): (0,2)
```

❮ C++ <complex> Library

5