# std::proj(std::complex)

< cpp‎ | numeric‎ | complex

C++
 Language Standard library headers Concepts Utilities library Strings library Containers library Algorithms library Iterators library Numerics library Input/output library Localizations library Regular expressions library (C++11) Atomic operations library (C++11) Thread support library (C++11) Filesystem library (C++17) Technical Specifications

Numerics library
 Common mathematical functions Special mathematical functions Floating-point environment (C++11) Complex numbers Numeric arrays Pseudo-random number generation Compile-time rational arithmetic (C++11) Numeric algorithms gcd(C++17) lcm(C++17) Generic numeric operations iota(C++11) accumulate inner_product adjacent_difference partial_sum

std::complex
Member functions
Non-member functions
 real imag abs arg norm conj proj(C++11) polar operator""ioperator""ifoperator""il(C++14)(C++14)(C++14)
Exponential functions
Power functions
Trigonometric functions
 asin(C++11) acos(C++11) atan(C++11)
Hyperbolic functions
 asinh(C++11) acosh(C++11) atanh(C++11)

 Defined in header template< class T > complex proj( const complex& z ); (1) (since C++11) std::complex proj( long double z ); (2) (since C++11) template< class DoubleOrInteger > std::complex proj( DoubleOrInteger z ); (3) (since C++11) std::complex proj( float z ); (4) (since C++11)

Returns the projection of the complex number z onto the Riemann sphere.

For most z, std::proj(z)==z, but all complex infinities, even the numbers where one component is infinite and the other is NaN, become positive real infinity, (INFINITY, 0) or (INFINITY, -0). The sign of the imaginary (zero) component is the sign of std::imag(z).

Additional overloads are provided for float, double, long double, and all integer types, which are treated as complex numbers with zero imaginary component.

### Parameters

 z - complex value

### Return value

the projection of z onto the Riemann sphere

### Notes

The proj function helps model the Riemann sphere by mapping all infinities to one (give or take the sign of the imaginary zero), and should be used just before any operation, especially comparisons, that might give spurious results for any of the other infinities.

### Example

#include <iostream>
#include <complex>

int main()
{
std::complex<double> c1(1, 2);
std::cout << "proj" << c1 << " = " << std::proj(c1) << '\n';

std::complex<double> c2(INFINITY, -1);
std::cout << "proj" << c2 << " = " << std::proj(c2) << '\n';

std::complex<double> c3(0, -INFINITY);
std::cout << "proj" << c3 << " = " << std::proj(c3) << '\n';
}

Output:

proj(1,2) = (1,2)
proj(inf,-1) = (inf,-0)
proj(0,-inf) = (inf,-0)