std::norm(std::complex)(3)
π std::norm(std::complex) π
okay so bestie, welcome to the C++ Standard Libary page for std::norm(std::complex) β yes, the name says it twice, itβs giving main-character self-title energy β¨. This one is all about the squared-magnitude side of complex numbers, and honestly? it ate. Letβs get into it π.
β¨ NAME β¨
std::norm(std::complex) - std::norm(std::complex)
β¨ Synopsis β¨
Defined in header <complex>
The main overload, aka the (1) one π:
template< class T >
T norm( const std::complex<T>& z );
(until C++20)
template< class T >
constexpr T norm( const std::complex<T>& z );
(since C++20)
Additional overloads (since C++11) β also defined in header <complex> π¦:
Until C++20, these non-constexpr floating-point besties:
float norm( float f );
double norm( double f );
long double norm( long double f );
(until C++20)
Since C++20 and until C++23, the constexpr float/double/long double squad β label (A) energy π₯:
constexpr float norm( float f );
constexpr double norm( double f );
constexpr long double norm( long double f );
(since C++20) (until C++23) (A)
Since C++23, the template floating-point one enters the chat π:
template< class FloatingPoint >
constexpr FloatingPoint norm( FloatingPoint f );
(since C++23)
Integer overloads, because inclusivity π:
template< class Integer >
double norm( Integer i );
(until C++20)
template< class Integer >
constexpr double norm( Integer i );
(since C++20) (B)
(1) Returns the squared magnitude of the complex number z β¨.
A,B) Additional overloads are provided for all integer and floating-point types, which are treated as complex numbers with zero imaginary component. (since C++11) π«Ά
β¨ Parameters β¨
zβ complex value πfβ floating-point value πΈiβ integer value π
β¨ Return value β¨
(1)The squared magnitude ofzπ(A)The square offπ₯(B)The square ofiβ
β¨ Notes β¨
The norm calculated by this function is also known as field norm or absolute square β iconic terminology, no cap π§.
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). lowkey a useful swap π‘.
The additional overloads are not required to be provided exactly as (A,B). They only need to be sufficient to ensure that for their argument num:
- If
numhas a standard (until C++23) floating-point typeT, thenstd::norm(num)has the same effect asstd::norm(std::complex<T>(num))π. - Otherwise, if
numhas an integer type, thenstd::norm(num)has the same effect asstd::norm(std::complex<double>(num))π.
β¨ Example β¨
run this, bestie πββοΈπ¨:
#include <cassert>
#include <complex>
#include <iostream>
int main()
{
constexpr std::complex<double> z {3.0, 4.0};
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) π
xoxo, your C++ bestie π β source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::norm(std::complex)(3)
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms