The C++ std::complex::arg() function is used to return the phase angle of a complex number, returning it as a value in radians. It represents the angle between the positive real axis and the line formed by the origin and the complex number in the complex plane.
SyntaxThe result is expressed in radians and ranges from -22/7(-pi) to +22/7(+pi).
Following is the syntax for std::complex::arg() function.
arg (const complex<T>& x); double arg (ArithmeticType x);Parameters
It returns the phase angle of the complex number x.
Exceptionsnone
Example 1In the following example, we are going to consider the basic usage of the arg() function.
#include <iostream> #include <complex> int main() { std::complex < double > x(1.0, 1.2); std::cout << "Result : " << std::arg(x) << " radians" << std::endl; return 0; }Output
If we run the above code it will generate the following output −
Result : 0.876058 radiansExample 2
Consider the following example, where we are going to take argument of negative complex number.
#include <iostream> #include <complex> int main() { std::complex < double > a(-2.1, -1.2); std::cout << "Result : " << std::arg(a) << " radians" << std::endl; return 0; }Output
Following is the output of the above code −
Result : -2.62245 radiansExample 3
Let's look at the following example, where we are going to consider the argument of real complex part.
#include <iostream> #include <complex> int main() { std::complex < double > a(3.0, 0.0); std::cout << "Result : " << std::arg(a) << " radians" << std::endl; return 0; }Output
Output of the above code is as follows −
Result : 0 radians
complex.htm
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