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

creall函数


概要:
#include <complex.h>
long double creall(long double complex z);

描述:

该函数计算参数z的实部值。

对于复数变量z,表达式z和表达式CMPLXL(creall(z), cimagl(z))是等价表达式。如果实现支持虚数类型,表达式z和表达式creall(z)+cimagl(z)*I是等价表达式。


参数:
long double complex z

参数为long double complex类型的复数。


返回值:

函数返回参数z的实部值。


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

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

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

int main(void)
{
    long double complex x = 1.0L + 2.0LI;
    long double y;
    char *ptr = "creall(1.0L + 2.0Li)";

    y = creall(x);
    printf("%s = %.2Lf\n", ptr, y);

    return 0;
}

输出:

creall(1.0L + 2.0Li) = 1.00


相关内容:
creal 计算double complex类型复数实部值的函数。
crealf 计算float complex类型复数实部值的函数。


主要参考资料:

1、ISO/IEC 9899:2024

2、ISO/IEC 9899:2018