C++ Standard Library C++ STL Library

C++ <complex> - arg() Function



The C++ <complex> arg() function returns the phase angle of a complex number, expressed in radians. It is equivalent to atan2(x.imag(),x.real()). The returned value lies in the range [-𝜋, 𝜋].

The additional overloads is added in C++11 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 arg (const complex<T>& z);
template<class T> T arg (const complex<T>& z); 

//additional overloads
double arg (ArithmeticType z);

Parameters

z Specify a complex value.

Return Value

Returns the phase angle of the complex number.

Example:

The example below shows the usage of <complex> arg() 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 phase angle 
  cout<<"arg(z1): "<<arg(z1)<<"\n";
  cout<<"arg(z2): "<<arg(z2)<<"\n";
  cout<<"arg(z3): "<<arg(z3)<<"\n";

  return 0;
}

The output of the above code will be:

arg(z1): 0.785398
arg(z2): 0
arg(z3): 1.5708

❮ C++ <complex> Library