CMPLXF, CMPLX, CMPLXL
来自 cppreference.cn
定义在头文件 <complex.h> 中 |
||
float complex CMPLXF( float real, float imag ); |
(C11 起) | |
double complex CMPLX( double real, double imag ); |
(C11 起) | |
long double complex CMPLXL( long double real, long double imag ); |
(C11 起) | |
这些宏中的每一个都扩展为一个表达式,其计算结果为指定复数类型的值,其实部具有 real
的值(转换为指定的参数类型),虚部具有 imag
的值(转换为指定的参数类型)。
只要表达式 real
和 imag
也适合,这些表达式就适合用作具有静态或线程存储持续时间对象的初始化器。
目录 |
[编辑] 参数
real | - | 要返回的复数的实部 |
imag | - | 要返回的复数的虚部 |
[编辑] 返回值
一个复数,由 real
作为实部和 imag
作为虚部组成。
[编辑] 注意
这些宏的实现方式就好像支持虚数类型一样(即使它们在其他情况下不支持且 _Imaginary_I 实际上未定义),并如下定义:
#define CMPLX(x, y) ((double complex)((double)(x) + _Imaginary_I * (double)(y))) #define CMPLXF(x, y) ((float complex)((float)(x) + _Imaginary_I * (float)(y))) #define CMPLXL(x, y) ((long double complex)((long double)(x) + \ _Imaginary_I * (long double)(y)))
[编辑] 示例
运行此代码
输出
z = 0.0-0.0i
[编辑] 参考
- C11 标准 (ISO/IEC 9899:2011)
- 7.3.9.3 CMPLX 宏 (p: 197)
[编辑] 另请参阅
(C99) |
虚数单位常量 i (宏常量) |
C++ 文档,关于 complex
|