I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
ComputingCComplex

abs

Absolute value of a complex number
+ View other versions (3)

Interface

#include <complex> 
double abs (complex<T> z)

Description

The abs function returns the absolute value of the complex number \inline  z = a + {\rm i} b. The result is the real number denoted by \inline |z| and defined through:

Example:
Example - Abs
Problem
This program returns the absolute value of the complex number z=0.5+2i.
Workings
#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;
}
Solution
Output:

|0.5 + 2 i| = 2.0616

Note

The function is actually an alias for hypot(a, b) = \inline \sqrt{a^2 + b^2}.