The cimag functions (C99) - cimag, cimagf, cimagl

複素数の虚部 (imaginary part) を返します.

cimag (C99)

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

cimag 関数は,double complex 型の複素数 z の虚部を double 型で返します.

cimagf (C99)

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

cimagf 関数は,float complex 型の複素数 z の虚部を float 型で返します.

cimagl (C99)

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

cimagl 関数は,long double complex 型の複素数 z の虚部を long double 型で返します.

戻り値

  • 複素数の虚部

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

以下に cimag 関数を使用して複素数の虚部を求めるサンプルプログラムを示します.

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

/* main */
int main(void) {
    double complex z = 3.0 + 2.0 * I;
    double im;

    /* 虚部を取得 */
    im = cimag(z);
    printf("虚部: %.1f\n", im);

    return EXIT_SUCCESS;
}

実行例

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

虚部: 2.0