命名空间
变体
操作

_Complex_I

来自 cppreference.cn
< c‎ | numeric‎ | complex
定义于头文件 <complex.h>
#define _Complex_I /* unspecified */
(since 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

[编辑] 参考文献

  • C23 标准 (ISO/IEC 9899:2024)
  • 7.3.1/4 _Complex_I (页码: 待定)
  • C17 标准 (ISO/IEC 9899:2018)
  • 7.3.1/4 _Complex_I (页码: 136)
  • C11 标准 (ISO/IEC 9899:2011)
  • 7.3.1/4 _Complex_I (页码: 188)
  • C99 标准 (ISO/IEC 9899:1999)
  • 7.3.1/2 _Complex_I (页码: 170)

[编辑] 参见

虚数单位常量 i
(宏常量) [编辑]
(C99)
复数或虚数单位常量 i
(宏常量) [编辑]