cargf, carg, cargl

来自cppreference.com
< c‎ | numeric‎ | complex
定义于头文件 <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 complexlong double imaginarylong double类型,则调用cargl。若z拥有float complexfloat imaginaryfloat类型,则调用cargf。若z拥有double complexdouble imaginarydouble或任何整数类型,则调用carg

目录

[编辑] 参数

z - 复参数

[编辑] 返回值e

若无错误发生,则返回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); // 或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 standard (ISO/IEC 9899:2011):
  • 7.3.9.1 The carg functions (p: 196)
  • 7.25 Type-generic math <tgmath.h> (p: 373-375)
  • G.7 Type-generic math <tgmath.h> (p: 545)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.3.9.1 The carg functions (p: 178)
  • 7.22 Type-generic math <tgmath.h> (p: 335-337)
  • G.7 Type-generic math <tgmath.h> (p: 480)

[编辑] 参阅

(C99)
(C99)
(C99)
计算复数的模(绝对值)
(函数) [编辑]
计算反正切,以符号确定象限
(函数) [编辑]
argC++ 文档