- complex[meta header]
- std[meta namespace]
- function template[meta id-type]
namespace std {
template <class T>
T
norm(const complex<T>& x); // (1) C++03
template <class T>
constexpr T
norm(const complex<T>& x); // (1) C++20
complex<Promoted>
norm(Arithmetic x); // (2) C++11
constexpr complex<Promoted>
norm(Arithmetic x); // (2) C++26
}- Promoted[italic]
- Arithmetic[italic]
複素数体のノルム(field norm。絶対値の 2 乗)を得る。
- (1) :
complex<T>に対するオーバーロード - (2) : 算術型に対する追加のオーバーロード
(2)は、以下のように振る舞う:
- 実引数の型が浮動小数点数型
Tの場合、complex<T>にキャストされているかのように振る舞う - そうでなくて、実引数が整数型の場合、
complex<double>にキャストされているかのように振る舞う (C++23)
また、これらの追加のオーバーロードが関数テンプレートなのか否か、あるいは、引数が参照型なのか否かなどについては、規格では何も言及されていない。
引数 x のノルム
#include <iostream>
#include <complex>
int main()
{
std::complex<double> c(1.0, 2.0);
double result = std::norm(c);
std::cout << "norm( " << c << " ) = " << result << std::endl;
}- std::norm[color ff0000]
norm( (1,2) ) = 5
- C++98(追加のオーバーロードは C++11 から)
- Clang: 3.0, 3.1, 3.2, 3.3, 3.4(追加のオーバーロード含む)
- GCC: 4.3.6, 4.4.7, 4.5.4, 4.6.4, 4.7.3, 4.8.1, 4.8.2, 4.9.0(追加のオーバーロード以外)
- GCC: 4.3.6, 4.4.7, 4.5.4, 4.6.4, 4.7.3, 4.8.1, 4.8.2, 4.9.0(追加のオーバーロード含む)
- ICC: ??
- Visual C++: ??
| 名前 | 説明 |
|---|---|
real |
複素数の実部を得る。 |
imag |
複素数の虚部を得る。 |
abs |
複素数の絶対値を得る。 |
arg |
複素数の偏角を得る。 |
conj |
共役複素数を得る。 |
proj |
リーマン球面への射影を得る。 |
polar |
指定した絶対値と偏角の複素数値を得る。 |
- ノルム (体論) - Wikipedia
- ノルム - Wikipedia
- P0415R1 Constexpr for
std::complex - P1467R9 Extended floating-point types and standard names
- C++23で拡張浮動小数点数型への対応が行われ、整数型も考慮されるようになった
- P1383R2 More constexpr for
<cmath>and<complex>- C++26で(2)が
constexpr対応した
- C++26で(2)が