首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

_Complex_I

在头文件<complex.h>中定义

#define _Complex_I / *未指定* /

(自C99以来)

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

注意

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

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

代码语言:javascript
复制
#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));
}

可能的输出:

代码语言:javascript
复制
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):
    • 7.3.1 / 4 _Complex_I(p:188)
  • C99标准(ISO / IEC 9899:1999):
    • 7.3.1 / 2 _Complex_I(p:170)

扩展内容

_Imaginary_I(C99)

虚数单位常数i(宏常数)

I(C99)

复数或虚数单位常数i(宏常数)

扫码关注腾讯云开发者

领取腾讯云代金券