std::norm(std::complex)(3)

NAME
std::norm(std::complex) - std::norm(std::complex)

Synopsis
   Defined in header <complex>
   template< class T > (until C++20)
   T norm( const std::complex<T>& z );
   template< class T > (since C++20)
   constexpr T norm( const std::complex<T>& z );
   float norm( float z );
   template< class DoubleOrInteger > (since C++11)
   double norm( DoubleOrInteger z ); (1) (until C++20)
   long double norm( long double z ); (2)
   constexpr float norm( float z );
   template< class DoubleOrInteger > (since C++20)
   constexpr double norm( DoubleOrInteger z );
   constexpr long double norm( long double z );
   1) Returns the squared magnitude of the complex number z.
   2) Additional overloads are provided for float, double, long double,
   and all integer types, which are treated as complex numbers with zero (since C++11)
   imaginary component.

Parameters
   z - complex value

Return value
   the squared magnitude of z

Notes
   The norm calculated by this function is also known as field norm or absolute square.
   The Euclidean norm of a complex number is provided by std::abs, which is more costly
   to compute. In some situations, it may be replaced by std::norm, for example, if
   abs(z1) > abs(z2) then norm(z1) > norm(z2).

Example
// Run this code
 #include <cassert>
 #include <complex>
 #include <iostream>
 int main()
 {
     constexpr std::complex<double> z{3, 4};
     static_assert(std::norm(z) == (z.real() * z.real() + z.imag() * z.imag()));
     static_assert(std::norm(z) == (z * std::conj(z)));
            assert(std::norm(z) == (std::abs(z) * std::abs(z)));
     std::cout << "std::norm(" << z << ") = " << std::norm(z) << '\n';
 }

Output:
 std::norm((3,4)) = 25

See also
   abs(std::complex) returns the magnitude of a complex number
                     (function template)
   conj returns the complex conjugate
                     (function template)
   polar constructs a complex number from magnitude and phase angle
                     (function template)