?
This document uses PHP Chinese website manual Release
在頭文件<math.h>中定義 | ||
---|---|---|
float complex CMPLXF( float real, float imag ); | (since C11) | |
double complex CMPLX( double real, double imag ); | (since C11) | |
long double complex CMPLXL( long double real, long double imag ); | (since C11) |
這些宏中的每一個都擴展為一個表達式,該表達式的值為指定的復合類型的值,實部的值為real
(轉(zhuǎn)換為指定的參數(shù)類型),虛部的值為imag
(轉(zhuǎn)換為指定的參數(shù)類型)。
該表達式是適合用作初始化用于與靜態(tài)或線程存儲時限的物體,只要表達式real
和imag
也是合適的。
真實 | - | 復數(shù)的實際部分返回 |
---|---|---|
圖片 | - | 復數(shù)的虛數(shù)部分返回 |
復數(shù)組成real
和imag
作為實部和虛部。
這些宏被實現(xiàn),就好像虛構(gòu)類型被支持(即使它們否則不被支持并且_Imaginary_I
實際上是未定義的)并且如同如下定義:
#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)))
#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標準(ISO / IEC 9899:2011):
7.3.9.3 CMPLX宏(p:197)