C++ Complex Library - Abs


Advertisements

Description

It is an absolute value of complex and returns the absolute value of the complex number x.

Declaration

Following is the declaration for std::abs.

template<class T> T abs (const complex<T>& x);

Parameters

x It is a complex value.

Return Value

It returns the absolute value of the complex number x.

Exceptions

none

Example

In below example for std::abs.

#include <iostream>     
#include <complex>      

int main () {
   std::complex<double> mycomplex (1.0,4.0);

   std::cout << "The absolute value of " << mycomplex << " is " << std::abs(mycomplex) 
      << '\n';
   return 0;
}

The sample output should be like this −

The absolute value of (1,4) is 4.12311
complex.htm
Advertisements