当前位置: C语言 -- 标准库 -- <complex.h> -- CMPLXF

CMPLXF宏


概要:
#include <complex.h>
float complex CMPLXF(float x, float y);

描述:

该宏是一个函数式宏,可以构造一个float complex类型的复数,该复数实数部分具有参数x的值,虚数部分具有参数y的值。

构造得到的复数应适合初始化具有静态存储期限的对象或者线程存储期限的对象,前提是两个参数都合适。

CMPLXF的实现就像实现支持虚数类型一样,其定义如下所示:

#define CMPLXF(x, y) ((float complex)((float)(x) + _Imaginary_I*(float)(y)))


参数:
float x

参数为一个float类型的浮点数。

float y

参数为一个float类型的浮点数。


返回值:

该宏返回x + iy


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
/*宏CMPLXF范例*/

#ifdef __STDC_NO_COMPLEX__
#error "Implementation does not support complex types."
#endif

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

int main(void)
{
    float x = 1.0f;
    float y = 2.0f;
    float complex z;
    char *ptr = "CMPLXF(1.0f, 2.0f)";

    z = CMPLXF(x, y);
    printf("%s = %.2f + %.2fi\n", ptr, crealf(z),cimagf(z));

    return 0;
}

输出:

CMPLXF(1.0f, 2.0f) = 1.00 + 2.00i

:使用ideone编译。


相关内容:
CMPLX 构造double complex类型复数的宏。
CMPLXL 构造long double complex类型复数的宏。