Namespaces
Variants

cargf, carg, cargl

From cppreference.net
定义于头文件 <complex.h>
float cargf ( float complex z ) ;
(1) (C99 起)
double carg ( double complex z ) ;
(2) (C99 起)
long double cargl ( long double complex z ) ;
(3) (C99 起)
定义于头文件 <tgmath.h>
#define carg( z )
(4) (C99 起)
1-3) 计算 z 的辐角(亦称相位角),其分支切割线位于负实轴。
4) 类型泛型宏:若 z 具有类型 long double complex long double imaginary long double ,则调用 cargl 。若 z 具有类型 float complex float imaginary float ,则调用 cargf 。若 z 具有类型 double complex double imaginary double 或任何整数类型,则调用 carg

目录

参数

z - 复参数

返回值

若无错误发生,返回 z 在区间 [−π; π] 内的相位角。

错误和特殊情况的处理方式如同该函数实现为 atan2 ( cimag ( z ) , creal ( z ) )

示例

#include <stdio.h>
#include <complex.h>
int main(void) 
{
    double complex z1 = 1.0+0.0*I;
    printf("phase angle of %.1f%+.1fi is %f\n", creal(z1), cimag(z1), carg(z1));
    double complex z2 = 0.0+1.0*I;
    printf("phase angle of %.1f%+.1fi is %f\n", creal(z2), cimag(z2), carg(z2));
    double complex z3 = -1.0+0.0*I;
    printf("phase angle of %.1f%+.1fi is %f\n", creal(z3), cimag(z3), carg(z3));
    double complex z4 = conj(z3); // or CMPLX(-1, -0.0)
    printf("phase angle of %.1f%+.1fi (the other side of the cut) is %f\n",
             creal(z4), cimag(z4), carg(z4));
}

输出:

phase angle of 1.0+0.0i is 0.000000
phase angle of 0.0+1.0i is 1.570796
phase angle of -1.0+0.0i is 3.141593
phase angle of -1.0-0.0i (the other side of the cut) is -3.141593

参考文献

  • C11 标准 (ISO/IEC 9899:2011):
  • 7.3.9.1 carg 函数 (第 196 页)
  • 7.25 泛型数学 <tgmath.h> (第 373-375 页)
  • G.7 泛型数学 <tgmath.h> (第 545 页)
  • C99 标准 (ISO/IEC 9899:1999):
  • 7.3.9.1 carg 函数 (第 178 页)
  • 7.22 泛型数学 <tgmath.h> (第 335-337 页)
  • G.7 泛型数学 <tgmath.h> (第 480 页)

参阅

(C99) (C99) (C99)
计算复数的模
(函数)
计算反正切,使用符号确定象限
(函数)
C++ 文档 for arg