Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::proj(std::complex)

      From cppreference.com
      <cpp‎ |numeric‎ |complex
       
       
       
       
      Defined in header<complex>
      template<class T>
      std::complex<T> proj(conststd::complex<T>& z);
      (1)(since C++11)
      Defined in header<complex>
      (A)
      std::complex<float>       proj(float f);

      std::complex<double>      proj(double f);

      std::complex<longdouble> proj(longdouble f);
      (until C++23)
      template<class FloatingPoint>
      std::complex<FloatingPoint> proj( FloatingPoint f);
      (since C++23)
      template<class Integer>
      std::complex<double> proj( Integer i);
      (B)
      1) Returns the projection of the complex numberz onto theRiemann sphere.
      For mostz,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 ofstd::imag(z).
      A,B) Additional overloads are provided for all integer and floating-point types, which are treated as complex numbers with positive zero imaginary component.

      Contents

      [edit]Parameters

      z - complex value
      f - floating-point value
      i - integer value

      [edit]Return value

      1) The projection ofz onto the Riemann sphere.
      A) The projection ofstd::complex(f) onto the Riemann sphere.
      B) The projection ofstd::complex<double>(i) onto the Riemann sphere.

      [edit]Notes

      Theproj 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 argumentnum:

      • Ifnum has astandard(until C++23) floating-point typeT, thenstd::proj(num) has the same effect asstd::proj(std::complex<T>(num)).
      • Otherwise, ifnum has an integer type, thenstd::proj(num) has the same effect asstd::proj(std::complex<double>(num)).

      [edit]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)

      [edit]See also

      returns the magnitude of a complex number
      (function template)[edit]
      returns the squared magnitude
      (function template)[edit]
      constructs a complex number from magnitude and phase angle
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/complex/proj&oldid=150886"

      [8]ページ先頭

      ©2009-2025 Movatter.jp