当前位置: C语言 -- 标准库 -- <complex.h> -- _Imaginary_I

_Imaginary_I宏


概要:

#define _Imaginary_I constant-expression


描述:

该宏会扩展为const float _Imaginary类型的、值为虚数单位的常量表达式。

当且仅当实现支持虚数类型时,宏_Imaginary_I才会被定义。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
/*宏_Imaginary_I范例*/

#ifdef __STDC_NO_COMPLEX__
#error "Implementation does not support complex types."
#endif

#include <complex.h>
#include <stdio.h>

int main(void)
{
    double complex x = 1.0 + 2.0*_Imaginary_I;
    double complex y = 2.3 + 1.5*_Imaginary_I;
    double complex z;

    z = x + y;
    printf("z = %.2f + %.2fi\n",creal(z),cimag(z));

    return 0;
}


可能输出:

z = 3.30 + 3.50i

:由于目前编译器对虚数的支持都不够理想,上述程序的运行结果并未得到验证。


相关内容:
imaginary 表示虚数类型的宏。