std::abs(std::complex) - cppreference.com (original) (raw)

| | | | | --------------------------------------------------- | | | | template< class T > T abs( const complex<T>& z ); | | |

Returns the magnitude of the complex number z.

[edit] Parameters

[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 #include   int main() { std::complex 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

arg returns the phase angle (function template) [edit]
polar constructs a complex number from magnitude and phase angle (function template) [edit]
abs(int)labsllabs(C++11) computes absolute value of an integral value (\(\small{|x
abs(float)fabsfabsffabsl(C++11)(C++11) absolute value of a floating point value (\(\small{|x
hypothypotfhypotl(C++11)(C++11)(C++11) computes hypotenuse \(\scriptsize{\sqrt{x^2+y^2}}\)√x2+y2 and \(\scriptsize{\sqrt{x^2+y^2+z^2}}\)√x2+y2+z2(since C++17) (function) [edit]
abs(std::valarray) applies the function abs to each element of valarray (function template) [edit]
C documentation for cabs