The carg functions (C99) - carg, cargf, cargl

複素平面上の偏角 (argument) [位相角 (phase angle) ともいう] を計算します.

carg (C99)

#include <complex.h>
double carg(
    double complex z
);

carg 関数は,double complex 型の引数 z の偏角を計算し,結果を double 型で返します.

cargf (C99)

#include <complex.h>
float cargf(
    float complex z
);

cargf 関数は,float complex 型の引数 z の偏角を計算し,結果を float 型で返します.

cargl (C99)

#include <complex.h>
long double cargl(
    long double complex z
);

cargl 関数は,long double complex 型の引数 z の偏角を計算し,結果を long double 型で返します.

carg,cargf,cargl 関数は負の実軸に沿って分岐切断線をもちます.

戻り値

  • 区間 [- pi, + pi] を値域とする偏角

C言語サンプルプログラム

以下に carg 関数を使用して複素平面上の偏角を計算するサンプルプログラムを示します.

/* header files */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <complex.h>

/* macros */
#define PI 3.14159265

/* main */
int main(void) {
    double r = 2.0;
    double complex z;

    z = r * (cos(PI) + sin(PI) * I);
    printf("arg: %.5f\n", carg(z));

    return EXIT_SUCCESS;
}

実行例

サンプルプログラムの実行結果は以下のようになります.

arg: 3.14159