csqrtf, csqrt, csqrtl
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <complex.h> で定義
|
||
float complex csqrtf( float complex z ); |
(1) | (C99以上) |
double complex csqrt( double complex z ); |
(2) | (C99以上) |
long double complex csqrtl( long double complex z ); |
(3) | (C99以上) |
| ヘッダ <tgmath.h> で定義
|
||
#define sqrt( z ) |
(4) | (C99以上) |
1-3) 負の実軸に沿った分岐切断を持つ、
z の複素平方根を計算します。4) 型総称マクロ。
z が long double complex の場合は csqrtl が呼ばれ、 z が double complex 型の場合は csqrt が呼ばれ、 z が float complex 型の場合は csqrtf が呼ばれます。 z が実数または整数の場合、このマクロは対応する実数の関数 (sqrtf、 sqrt、 sqrtl) を呼びます。 z が虚数の場合は、対応する複素数版が呼ばれます。引数
| z | - | 複素数の引数 |
戻り値
エラーが発生しなければ、 z の平方根を返します。 戻り値は虚軸を含む右半平面 (実部が [0; +∞) で虚部が (−∞; +∞)) の範囲内になります。
エラー処理および特殊な値
エラーは math_errhandling と一貫性があるように報告されます。
処理系が IEEE 浮動小数点算術をサポートしている場合、
- この関数は虚部の符号を考慮すれば分岐切断上で連続的です。
csqrt(conj(z)) == conj(csqrt(z))です。zが±0+0iであれば、結果は+0+0iです。zがx+∞i(x が NaN の場合も含む) であれば、結果は+∞+∞iです。zがx+NaNi(x が ±∞ の場合は除く) であれば、結果はNaN+NaNiであり、 FE_INVALID が発生するかもしれません。zが-∞+yi(ただし y は有限な正の値) であれば、結果は+0+∞iです。zが+∞+yi(ただし y は有限な正の値) であれば、結果は+∞+0i)です。zが-∞+NaNiであれば、結果はNaN±∞i(虚部の符号は未規定) です。zが+∞+NaNiであれば、結果は+∞+NaNiです。zがNaN+yiであれば、結果はNaN+NaNiであり、 FE_INVALID が発生するかもしれません。zがNaN+NaNiであれば、結果はNaN+NaNiです。
例
Run this code
#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex z1 = csqrt(-4);
printf("Square root of -4 is %.1f%+.1fi\n", creal(z1), cimag(z1));
double complex z2 = csqrt(conj(-4)); // or, in C11, CMPLX(-4, -0.0)
printf("Square root of -4-0i, the other side of the cut, is "
"%.1f%+.1fi\n", creal(z2), cimag(z2));
}
出力:
Square root of -4 is 0.0+2.0i
Square root of -4-0i, the other side of the cut, is 0.0-2.0i
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.3.8.3 The csqrt functions (p: 196)
- 7.25 Type-generic math <tgmath.h> (p: 373-375)
- G.6.4.2 The csqrt functions (p: 544)
- G.7 Type-generic math <tgmath.h> (p: 545)
- C99 standard (ISO/IEC 9899:1999):
- 7.3.8.3 The csqrt functions (p: 178)
- 7.22 Type-generic math <tgmath.h> (p: 335-337)
- G.6.4.2 The csqrt functions (p: 479)
- G.7 Type-generic math <tgmath.h> (p: 480)
関連項目
(C99)(C99)(C99) |
複素冪関数を計算します (関数) |
(C99)(C99) |
平方根 (√x) を計算します (関数) |
sqrt の C++リファレンス
| |