名稱空間
變體
操作

cargf, carg, cargl

來自 cppreference.com
< c‎ | 數值‎ | 複數
定義在標頭檔案 <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 - 複數引數

[編輯] 返回值

如果未發生錯誤,則返回 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 函式 (p: 196)
  • 7.25 型別通用數學 <tgmath.h> (p: 373-375)
  • G.7 型別通用數學 <tgmath.h> (p: 545)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.3.9.1 carg 函式 (p: 178)
  • 7.22 型別通用數學 <tgmath.h> (p: 335-337)
  • G.7 型別通用數學 <tgmath.h> (p: 480)

[編輯] 另請參閱

(C99 起)(C99 起)(C99 起)
計算複數的模
(函式) [編輯]
(C99 起)(C99 起)
計算反正切,使用符號確定象限
(函式) [編輯]
C++ 文件,關於 arg