GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing cpprefjp.github.io — std::complex - cpprefjp C++日本語リファレンス class template <complex> std::complex
これ以外の型がテンプレート引数として与えられた場合、その動作は未規定である。 配列へのキャスト(C++11)
メンバ関数
メンバ型
非メンバ関数複素数の値
演算子
リテラル
数学関数の
|
| 名前 | 説明 | 対応バージョン |
|---|---|---|
acos |
複素数の逆余弦を求める | C++11 |
asin |
複素数の逆正弦を求める | C++11 |
atan |
複素数の逆正接を求める | C++11 |
acosh |
複素数の双曲線逆余弦を求める | C++11 |
asinh |
複素数の双曲線逆正弦を求める | C++11 |
atanh |
複素数の双曲線逆正接を求める | C++11 |
cos |
複素数の余弦を求める | |
cosh |
複素数の双曲線余弦を求める | |
exp |
自然対数の底 e の累乗(複素数)を求める。 | |
log |
複素数の自然対数を求める | |
log10 |
複素数の常用対数を求める | |
pow |
複素数の累乗を求める | |
sin |
複素数の正弦を求める | |
sinh |
複素数の双曲線正弦を求める | |
sqrt |
複素数の平方根を求める | |
tan |
複素数の正接を求める | |
tanh |
複素数の双曲線正接を求める |
| 名前 | 説明 | 対応バージョン |
|---|---|---|
tuple_size |
静的な要素数取得(class template) | C++26 |
tuple_element |
静的な要素の型取得(class template) | C++26 |
get |
要素を取得する(function template) | C++26 |
#include <iostream>
#include <complex>
float pi()
{
return 3.141593f;
}
int main()
{
// 実部1.0f、虚部2.0fの複素数オブジェクトを作る
std::complex<float> c(1.0f, 2.0f);
// ストリーム出力
std::cout << "output : " << c << std::endl;
// 各要素の取得
float real = c.real(); // 実部
float imag = c.imag(); // 虚部
std::cout << "real : " << real << std::endl;
std::cout << "imag : " << imag << std::endl;
// 演算
std::complex<float> a(1.0f, 2.0f);
std::complex<float> b(2.0f, 3.0f);
std::cout << "a + b : " << a + b << std::endl;
std::cout << "a - b : " << a - b << std::endl;
std::cout << "a * b : " << a * b << std::endl;
std::cout << "a / b : " << a / b << std::endl;
// 各複素数の値を取得する
std::cout << "abs : " << std::abs(c) << std::endl; // 絶対値
std::cout << "arg : " << std::arg(c) << std::endl; // 偏角
std::cout << "norm : " << std::norm(c) << std::endl; // ノルム
std::cout << "conj : " << std::conj(c) << std::endl; // 共役複素数
std::cout << "proj : " << std::proj(c) << std::endl; // リーマン球面への射影
std::cout << "polar : " << std::polar(1.0f, pi() / 2.0f); // 極座標(絶対値:1.0、偏角:円周率÷2.0)から複素数を作る
}
output : (1,2)
real : 1
imag : 2
a + b : (3,5)
a - b : (-1,-1)
a * b : (-4,7)
a / b : (0.615385,0.0769231)
abs : 2.23607
arg : 1.10715
norm : 5
conj : (1,-2)
proj : (1,2)
polar : (-1.62921e-07,1)
#include <print>
#include <complex>
#include <vector>
#include <ranges>
int main()
{
// 構造化束縛で各要素を取得する
{
std::complex<float> c{1.0f, 2.0f};
auto [real, imag] = c;
std::println("real:{} imag:{}", real, imag);
}
// 定数の添字を指定して各要素を取得する
{
std::complex<float> c{1.0f, 2.0f};
float real = std::get<0>(c);
float imag = std::get<1>(c);
std::println("real:{} imag:{}", real, imag);
}
// complexの配列から実部のみを抽出する
{
std::vector<std::complex<float>> v {
{1.0f, 2.0f},
{3.0f, 4.0f},
{5.0f, 6.0f}
};
for (float real : v | std::views::elements<0>) {
std::println("real:{}", real);
}
}
}
real:1 imag:2
real:1 imag:2
real:1
real:3
real:5
std::complex over-encapsulatedstd::complex型のメモリレイアウトが規定された経緯のレポートstd::complexにタプルインタフェースがサポートされた