C
数值 | Numerics

csqrtf

csqrtf, csqrt, csqrtl

在头文件中定义
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复合体,则调用csqrt,如果z具有类型float complex,则调用csqrtf。 如果z是实数或整数,那么宏调用相应的实函数(sqrtf,sqrt,sqrtl)。 如果z是虚数,则调用相应的复数版本。

参数

z-complex argument

返回值

如果不出现错误,则返回z右半平面范围内的平方根,包括沿着实轴的虚轴([0; +∞)和沿虚轴的(-∞; +∞)。) 。

错误处理和特殊值

报告的错误与math_errhandling一致。

如果实现支持IEEE浮点运算,

考虑到虚部的符号,该功能在分支切割上是连续的

#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):

扩展内容

cpowcpowfcpowl(C99)(C99)(C99)计算复数幂函数(函数)
sqrtsqrtfsqrtl(C99)(C99)计算平方根(√x)(函数)

| sqrt 的C ++文档|