cargf, carg, cargl
定义于头文件 <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); // 或 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) |
计算复数的模(绝对值) (函数) |
(C99)(C99) |
计算反正切,以符号确定象限 (函数) |