A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../numeric/complex/arg.html below:

std::arg(std::complex) - cppreference.com

(1) (A) float       arg( float f );

double      arg( double f );

long double arg( long double f );
(until C++23) template< class FloatingPoint >

FloatingPoint

            arg( FloatingPoint f );
(since C++23)

template< class Integer >
double      arg( Integer i );

(B)

1) Calculates the phase angle (in radians) of the complex number z.

A,B) Additional overloads are provided for all integer and floating-point types, which are treated as complex numbers with zero imaginary component.

(since C++11) [edit] Parameters z - complex value f - floating-point value i - integer value [edit] Return value

A) Zero if f is positive or +0, π if f is negative or -0, NaN otherwise.

B) Zero if i is non-negative, π if it is negative.

[edit] Notes

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:

[edit] Example
#include <complex>
#include <iostream>
 
int main() 
{
    std::complex<double> z1(1, 0);
    std::complex<double> z2(0, 0);
    std::complex<double> z3(0, 1);
    std::complex<double> z4(-1, 0);
    std::complex<double> z5(-1, -0.0);
    double f = 1.;
    int i = -1;
 
    std::cout << "phase angle of " << z1 << " is " << std::arg(z1) << '\n'
              << "phase angle of " << z2 << " is " << std::arg(z2) << '\n'
              << "phase angle of " << z3 << " is " << std::arg(z3) << '\n'
              << "phase angle of " << z4 << " is " << std::arg(z4) << '\n'
              << "phase angle of " << z5 << " is " << std::arg(z5) << " "
                 "(the other side of the cut)\n"
              << "phase angle of " << f << " is " << std::arg(f) << '\n'
              << "phase angle of " << i << " is " << std::arg(i) << '\n';
 
}

Output:

phase angle of (1,0) is 0
phase angle of (0,0) is 0
phase angle of (0,1) is 1.5708
phase angle of (-1,0) is 3.14159
phase angle of (-1,-0) is -3.14159 (the other side of the cut)
phase angle of 1 is 0
phase angle of -1 is 3.14159
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4