命名空间
变体
操作

cpowf, cpow, cpowl

来自 cppreference.cn
< c‎ | numeric‎ | complex
定义于头文件 <complex.h>
float complex       cpowf( float complex x, float complex y );
(1) (自 C99)
double complex      cpow( double complex x, double complex y );
(2) (自 C99)
long double complex cpowl( long double complex x, long double complex y );
(3) (自 C99)
定义于头文件 <tgmath.h>
#define pow( x, y )
(4) (自 C99)
1-3) 计算复数幂函数 xy
,第一个参数沿负实轴的分支切割。
4) 类型泛型宏:如果任何参数的类型为 long double complex,则调用 cpowl。如果任何参数的类型为 double complex,则调用 cpow。如果任何参数的类型为 float complex,则调用 cpowf。如果参数是实数或整数,则宏调用相应的实数函数 (powfpowpowl)。如果任何参数是虚数,则调用相应的复数版本。

目录

[编辑] 参数

x, y - 复数参数

[编辑] 返回值

如果没有错误发生,则返回复数幂 xy

错误和特殊情况的处理方式如同操作是通过 cexp(y*clog(x)) 实现的,但允许实现更仔细地处理特殊情况。

[编辑] 示例

#include <stdio.h>
#include <complex.h>
 
int main(void)
{    
    double complex z = cpow(1.0+2.0*I, 2);
    printf("(1+2i)^2 = %.1f%+.1fi\n", creal(z), cimag(z));
 
    double complex z2 = cpow(-1, 0.5);
    printf("(-1+0i)^0.5 = %.1f%+.1fi\n", creal(z2), cimag(z2));
 
    double complex z3 = cpow(conj(-1), 0.5); // other side of the cut
    printf("(-1-0i)^0.5 = %.1f%+.1fi\n", creal(z3), cimag(z3));
 
    double complex z4 = cpow(I, I); // i^i = exp(-pi/2)
    printf("i^i = %f%+fi\n", creal(z4), cimag(z4));
}

输出

(1+2i)^2 = -3.0+4.0i
(-1+0i)^0.5 = 0.0+1.0i
(-1-0i)^0.5 = 0.0-1.0i
i^i = 0.207880+0.000000i

[编辑] 参考文献

  • C11 标准 (ISO/IEC 9899:2011)
  • 7.3.8.2 cpow 函数 (页码:195-196)
  • 7.25 类型泛型数学 <tgmath.h> (页码:373-375)
  • G.6.4.1 cpow 函数 (页码:544)
  • G.7 类型泛型数学 <tgmath.h> (页码:545)
  • C99 标准 (ISO/IEC 9899:1999)
  • 7.3.8.2 cpow 函数 (页码:177)
  • 7.22 类型泛型数学 <tgmath.h> (页码:335-337)
  • G.6.4.1 cpow 函数 (页码:479)
  • G.7 类型泛型数学 <tgmath.h> (页码:480)

[编辑] 参见

(C99)(C99)(C99)
计算复数平方根
(函数) [编辑]
(C99)(C99)
计算一个数的给定次幂 (xy)
(函数) [编辑]
C++ 文档 关于 pow