CMPLXF, CMPLX, CMPLXL
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <complex.h> で定義
|
||
float complex CMPLXF( float real, float imag ); |
(C11以上) | |
double complex CMPLX( double real, double imag ); |
(C11以上) | |
long double complex CMPLXL( long double real, long double imag ); |
(C11以上) | |
これらのマクロは、 (指定された引数型に変換された) real の値を実部に持ち、 (指定された引数型に変換された) imag の値を虚部に持つ、指定された複素数型の値に評価される式に展開されます。
式 real および imag が静的またはスレッド記憶域期間を持つオブジェクトのための初期化子として使用するのに適していれば、これらのマクロの展開結果もそれらに適します。
引数
| real | - | 返す複素数値の実部 |
| imag | - | 返す複素数値の虚部 |
戻り値
実部および虚部として real および imag を持つ複素数。
ノート
これらのマクロは、もし虚数型がサポートされていたならば以下のように定義されたであろうかのように、実装されます。
#define CMPLX(x, y) ((double complex)((double)(x) + _Imaginary_I * (double)(y)))
#define CMPLXF(x, y) ((float complex)((float)(x) + _Imaginary_I * (float)(y)))
#define CMPLXL(x, y) ((long double complex)((long double)(x) + \
_Imaginary_I * (long double)(y)))
例
Run this code
#include <stdio.h>
#include <complex.h>
int main(void)
{
double complex z = CMPLX(0.0, -0.0);
printf("z = %.1f%+.1fi\n", creal(z), cimag(z));
}
出力:
z = 0.0-0.0i
参考文献
- C11 standard (ISO/IEC 9899:2011):
- 7.3.9.3 The CMPLX macros (p: 197)
関連項目
(C99) |
虚数単位 i を表す虚数型の定数 (マクロ定数) |
complex の C++リファレンス
| |