约 995 字

约 5 分钟

#C 语言标准库宏 CMPLX

下面以函数形式说明宏的调用接口。

#include <complex.h>

double complex CMPLX(double real, double imag);

说明

从两个实浮点值构造复数,实部和虚部各自转换到对应类型。

分别构造两个分量可以保留正负零,并避免用 real + imag * I 构造无穷分量时发生额外的浮点运算。

自 C11 起提供。

参数

  • real - 实部。
  • imag - 虚部系数。

返回值

  • 具有指定实部和虚部的复数。

#示例

使用 GCC 时,在链接命令末尾添加 -lm。

#include <complex.h>
#include <stdio.h>

int main(void)
{
    double complex value = CMPLX(3.0, -4.0);
    printf("%Lg %Lg\n", (long double)creal(value), (long double)cimag(value));
    return 0;
}

运行结果。

3 -4

#相关接口

#参考标准

更新: 2026/11/28

作者: planc

创建: 2026/11/28