C
数值 | Numerics

_Complex_I

_Complex_I

在头文件中定义
#define _Complex_I / *未指定* /(自C99以来)

_Complex_I宏扩展为类型为const float _Complex的虚数单元的值。

注意

当 I 不可用时,可能会使用此宏,例如应用程序未定义它时。

不像_Imaginary_ICMPLX,使用该宏来构造复数可能虚分量上失去零的符号。

#include <stdio.h> #include <complex.h> #undef I #define J _Complex_I // can be used to redefine I int main(void) { // can be used to construct a complex number double complex z = 1.0 + 2.0 * _Complex_I; printf("1.0 + 2.0 * _Complex_I = %.1f%+.1fi\n", creal(z), cimag(z) // sign of zero may not be preserved double complex z2 = 0.0 + -0.0 * _Complex_I; printf("0.0 + -0.0 * _Complex_I = %.1f%+.1fi\n", creal(z2), cimag(z2) }

可能的输出:

1.0 + 2.0 * _Complex_I = 1.0+2.0i 0.0 + -0.0 * _Complex_I = 0.0+0.0i

参考

  • C11标准(ISO / IEC 9899:2011):

扩展内容

_Imaginary_I(C99)虚数单位常数i(宏常数)
I(C99)复数或虚数单位常数i(宏常数)