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

CMPLXL宏


概要:
#include <complex.h>
long double complex CMPLXL(long double x, long double y);

描述:

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

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

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

#define CMPLXL(x, y) ((long double complex)((long double)(x) + _Imaginary_I*(long double)(y)))


参数:
long double x

参数为一个long double类型的浮点数。

long double y

参数为一个long double类型的浮点数。


返回值:

该宏返回x + iy


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

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

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

int main(void)
{
    long double x = 1.0L;
    long double y = 2.0L;
    long double complex z;
    char *ptr = "CMPLXL(1.0L, 2.0L)";

    z = CMPLXL(x, y);
    printf("%s = %.2Lf + %.2Lfi\n", ptr, creall(z),cimagl(z));

    return 0;
}

输出:

CMPLXL(1.0L, 2.0L) = 1.00 + 2.00i

:使用ideone编译。


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