The creal functions (C99) - creal, crealf, creall

複素数の実部 (real part) を返します.

creal (C99)

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

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

crealf (C99)

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

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

creall (C99)

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

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

戻り値

  • 複素数の実部

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

以下に creal 関数を使用して複素数の実部を取得するサンプルプログラムを示します.

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

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

    /* 実部を取得 */
    re = creal(z);
    printf("実部: %.1f\n", re);

    return EXIT_SUCCESS;
}

実行例

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

実部: 3.0