Namespaces
Variants

cpowf, cpow, cpowl

From cppreference.net
定义于头文件 <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) 计算复数幂函数 x y
,第一个参数的支割线沿负实轴。
4) 类型泛型宏:若任一参数具有类型 long double complex ,则调用 cpowl ;若任一参数具有类型 double complex ,则调用 cpow ;若任一参数具有类型 float complex ,则调用 cpowf 。若参数为实数或整数,则宏调用对应的实数函数( powf pow powl )。若任一参数为虚数,则调用对应的复数版本函数。

目录

参数

x, y - 复数参数

返回值

若无错误发生,则返回复数幂 x y

错误和特殊情况的处理方式如同该操作通过 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); // 分支切割的另一侧
    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)
计算数的幂次 ( x y )
(函数)
C++ 文档 for pow