_Complex_I
来自 cppreference.cn
定义在头文件 <complex.h> 中 |
||
#define _Complex_I /* 未指定 */ |
(C99 起) | |
_Complex_I
宏展开为一个 const float _Complex 类型的值,其值为虚数单位。
目录 |
[编辑] 注意
当 I 不可用时(例如当它被应用程序取消定义时),可以使用此宏。
与 _Imaginary_I 和 CMPLX 不同,使用此宏构造复数可能会丢失虚部的零的符号。
[编辑] 示例
运行此代码
#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 (p: TBD)
- C17 标准 (ISO/IEC 9899:2018)
- 7.3.1/4 _Complex_I (p: 136)
- 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)
[编辑] 参阅
(C99) |
虚数单位常量 i (宏常量) |
(C99) |
复数或虚数单位常量 i (宏常量) |