csqrtf, csqrt, csqrtl
來自 cppreference.com
| 定義在標頭檔案 <complex.h> 中 |
||
| (1) | (C99 起) | |
| (2) | (C99 起) | |
| (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,結果是NaN+NaNi(除非 x 是 ±∞),並且可能引發 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
[編輯] 示例
執行此程式碼
#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 標準 (ISO/IEC 9899:2011)
- 7.3.8.3 csqrt 函式 (p: 196)
- 7.25 型別通用數學 <tgmath.h> (p: 373-375)
- G.6.4.2 csqrt 函式 (p: 544)
- G.7 型別通用數學 <tgmath.h> (p: 545)
- C99 標準 (ISO/IEC 9899:1999)
- 7.3.8.3 csqrt 函式 (p: 178)
- 7.22 型別通用數學 <tgmath.h> (p: 335-337)
- G.6.4.2 csqrt 函式 (p: 479)
- G.7 型別通用數學 <tgmath.h> (p: 480)
[編輯] 另請參見
| (C99)(C99)(C99) |
計算複數冪函式 (函式) |
| (C99)(C99) |
計算平方根 (√x) (函式) |
| C++ 文件 用於 sqrt
| |