std::sqrt(std::complex)
提供: cppreference.com
| ヘッダ <complex> で定義
|
||
| template< class T > complex<T> sqrt( const complex<T>& z ); |
||
負の実軸に沿って分岐切断する、複素数 z の平方根を計算します。
目次 |
[編集] 引数
| z | - | 平方根を取る複素数 |
[編集] 戻り値
エラーが発生しなければ、 z の平方根を返します。 戻り値は虚軸を含む右半平面 (実部が [0; +∞) で虚部が (−∞; +∞)) の範囲内です。
[編集] エラー処理と特殊な値
Errors are reported consistent with math_errhandling
If the implementation supports IEEE floating-point arithmetic,
- The function is continuous onto the branch cut taking into account the sign of imaginary part
- std::sqrt(std::conj(z)) == std::conj(std::sqrt(z))
- If
zis(±0,+0), the result is(+0,+0) - If
zis(x,+∞), the result is(+∞,+∞)even if x is NaN - If
zis(x,NaN), the result is(NaN,NaN)(unless x is ±∞) and FE_INVALID may be raised - If
zis(-∞,y), the result is(+0,+∞)for finite positive y - If
zis(+∞,y), the result is(+∞,+0)for finite positive y - If
zis(-∞,NaN), the result is(NaN,∞)(sign of imaginary part unspecified) - If
zis(+∞,NaN), the result is(+∞,NaN) - If
zis(NaN,y), the result is(NaN,NaN)and FE_INVALID may be raised - If
zis(NaN,NaN), the result is(NaN,NaN)
[編集] ノート
この関数の意味論は C の関数 csqrt と一貫性を持つことが意図されています。
[編集] 欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
| DR | 適用先 | 発行時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2597 | C++98 | specification mishandles signed zero imaginary parts | erroneous requirement removed |
[編集] 例
Run this code
#include <iostream> #include <complex> int main() { std::cout << "Square root of -4 is " << std::sqrt(std::complex<double>(-4, 0)) << '\n' << "Square root of (-4,-0), the other side of the cut, is " << std::sqrt(std::complex<double>(-4, -0.0)) << '\n'; }
出力:
Square root of -4 is (0,2) Square root of (-4,-0), the other side of the cut, is (0,-2)
[編集] 関連項目
| 片方または両方の引数が複素数かもしれない複素冪関数 (関数テンプレート) | |
| (C++11)(C++11) |
平方根 (√x) を計算します (関数) |
| valarray の各要素に関数 std::sqrt を適用します (関数テンプレート) | |
| csqrt の C言語リファレンス
| |

