abs
absolute value of a complex number
You're viewing an older version of this page (#3449). View the current version.
NAME
abs
INTERFACE
#include <complex>
double abs(complex<T> z );
DESCRIPTION
The abs function returns the absolute value of the complex number .
The result is the real number denoted by
and defined through:
(1)
Example 1
#include <stdio.h>
#include <complex>
using std::complex;
int main()
{
complex<double> z;
z=0.5+2i;
printf("|0.5 + 2 i| = %.4lf\n", abs(z));
return 0;
}Output:
|0.5 + 2 i| = 2.0616The function is actually an alias for hypot(a, b) = sqrt(a*a + b*b).