std::abs(std::complex)
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Numerics library
Mathematical special functions (C++17)
Mathematical constants (C++20)
Basic linear algebra algorithms (C++26)
Data-parallel types (SIMD) (C++26)
Floating-point environment (C++11)
Bit manipulation (C++20)
Saturation arithmetic (C++26)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
(C++17)
std::complex
(until C++20)
(C++26)
(C++26)
(C++26)
Defined in header
<complex>
template< class T >
T abs( const complex<T>& z );
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
Run this code
#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
(C++11)(C++11)(C++11)
+y2
and \(\scriptsize{\sqrt{x^2+y^2+z^2}}\)√x2
+y2
+z2
(since C++17)
(function) [edit]
C documentation for cabs