std::proj(std::complex)(3)
π NAME
std::proj(std::complex) β std::proj(std::complex), periodt. This iconic lil page comes from the C++ Standard Libary manual (yes bestie, the header spells it like that, I'm not fixing it π
).
π Synopsis
Defined in header <complex>
template< class T > (1) (since
C++11)
std::complex<T> proj( const std::complex<T>& z );
Additional overloads (since C++11)
Defined in header <complex>
std::complex<float> proj( float f );
std::complex<double> proj( double f );
(until C++23)
std::complex<long double> proj( long double f ); (A)
template< class FloatingPoint >
(since C++23)
std::complex<FloatingPoint> proj( FloatingPoint f );
template< class Integer > (B)
std::complex<double> proj( Integer i );
Okay so (1) is the main character: it 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.0) or (INFINITY, -0.0). The sign of the imaginary (zero) component is the sign of std::imag(z). No cap π
A,B) Additional overloads are provided for all integer and floating-point types, which are treated as complex numbers with positive zero imaginary component.
πΈ Parameters
zβ complex valuefβ floating-point valueiβ integer value
β¨ Return value
1)β The projection ofzonto the Riemann sphere.A)β The projection ofstd::complex(f)onto the Riemann sphere.B)β The projection ofstd::complex<double>(i)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.
The additional overloads are not required to be provided exactly as (A,B). They only need to be sufficient to ensure that for their argument num:
- If
numhas a standard (until C++23) floating-point typeT, thenstd::proj(num)has the same effect asstd::proj(std::complex<T>(num)). - Otherwise, if
numhas an integer type, thenstd::proj(num)has the same effect asstd::proj(std::complex<double>(num)).
π₯ Example
// Run this code
#include <complex>
#include <iostream>
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)
π See also
abs(std::complex)β returns the magnitude of a complex number (function template)normβ returns the squared magnitude (function template)polarβ constructs a complex number from magnitude and phase angle (function template)- C documentation for
cproj
mwah π this page is from http://cppreference.com, version/date 2024.06.10, and it's literally std::proj(std::complex)(3) β go project some infinities, bestie π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms