csqrtf, csqrt, csqrtl
From cppreference.net
|
定义于头文件
<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)); // 或在 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 函数集 (第 196 页)
-
- 7.25 泛型数学 <tgmath.h> (第 373-375 页)
-
- G.6.4.2 csqrt 函数集 (第 544 页)
-
- G.7 泛型数学 <tgmath.h> (第 545 页)
- C99 标准 (ISO/IEC 9899:1999):
-
- 7.3.8.3 csqrt 函数集 (第 178 页)
-
- 7.22 泛型数学 <tgmath.h> (第 335-337 页)
-
- G.6.4.2 csqrt 函数集 (第 479 页)
-
- G.7 泛型数学 <tgmath.h> (第 480 页)
参考
|
(C99)
(C99)
(C99)
|
计算复数幂函数
(函数) |
|
(C99)
(C99)
|
计算平方根 (
√
x
)
(函数) |
|
C++ 文档
关于
sqrt
|
|