Namespaces
Variants
Actions

std::abs(std::complex)

From cppreference.com
< cpp‎ | numeric‎ | complex
 
C++
 
Numerics library
 
std::complex
Defined in header <complex>
template< class T >
T abs( const complex<T>& z );

Returns the magnitude of the complex number z.

Contents

[edit] Parameters

z - complex value

[edit] Return value

If no errors occur, returns the absolute value (also known as norm, modulus, or magnitude) of z.

Errors and special cases are handled as if the function is implemented as std::hypot(std::real(z), std::imag(z)).

[edit] Example

#include <complex>
#include <iostream>
 
int main()
{
    std::complex<double> z(1, 1);
    std::cout << z << " cartesian is rho = " << std::abs(z)
              << " theta = " << std::arg(z) << " polar\n";
}

Output:

(1,1) cartesian is rho = 1.41421 theta = 0.785398 polar

[edit] See also

returns the phase angle
(function template) [edit]
constructs a complex number from magnitude and phase angle
(function template) [edit]
computes absolute value of an integral value (|x|)
(function) [edit]
absolute value of a floating point value (|x|)
(function) [edit]
(C++11)(C++11)(C++11)
computes hypotenuse x2
+y2
and x2
+y2
+z2
(since C++17)
(function) [edit]
applies the function abs to each element of valarray
(function template) [edit]

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant