A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/complex/abs/ below:

function template

<complex>

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

Absolute value of complex

Returns the absolute value of the complex number x.

The absolute value of a complex number is its magnitude (or modulus), defined as the theoretical distance between the coordinates (real,imag) of x and (0,0) (applying the Pythagorean theorem).

This function is overloaded in <cstdlib> for integral types (see cstdlib abs), in <cmath> for floating-point types (see cmath abs), and in <valarray> for valarrays (see valarray abs).



Parameters
x
Complex value.

Return value The absolute value of x.
T is the type of the components of the complex type (i.e., its value type).

Example
1
2
3
4
5
6
7
8
9
10
11
12
// abs complex example
#include <iostream>     // std::cout
#include <complex>      // std::complex, std::abs

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

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

  return 0;
}

Output:
The absolute value of (3,4) is 5


See also
arg
Phase angle of complex (function template)
polar
Complex from polar components (function template)
abs (cstdlib)
Absolute value (function)

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