Namespaces
Variants

crealf, creal, creall

From cppreference.net
定义于头文件 <complex.h>
float crealf ( float complex z ) ;
(1) (C99 起)
double creal ( double complex z ) ;
(2) (C99 起)
long double creall ( long double complex z ) ;
(3) (C99 起)
定义于头文件 <tgmath.h>
#define creal( z )
(4) (C99 起)
1-3) 返回 z 的实部。
4) 类型泛型宏:若 z 具有类型 long double complex long double imaginary long double ,则调用 creall 。若 z 具有类型 float complex float imaginary float ,则调用 crealf 。若 z 具有类型 double complex double imaginary double 或任何整数类型,则调用 creal

目录

参数

z - 复参数

返回值

z 的实部。

此函数对所有可能的输入均有完整规范定义,且不受 math_errhandling 中所述任何错误条件的影响

注释

对于任意复数变量 z z == creal ( z ) + I * cimag ( z )

示例

#include <stdio.h>
#include <complex.h>
int main(void)
{    
    double complex z = 1.0 + 2.0*I;
    printf("%f%+fi\n", creal(z), cimag(z));
}

输出:

1.000000+2.000000i

参考文献

  • C11 标准 (ISO/IEC 9899:2011):
  • 7.3.9.6 creal 函数 (第 198-199 页)
  • 7.25 泛型数学 <tgmath.h> (第 373-375 页)
  • G.7 泛型数学 <tgmath.h> (第 545 页)
  • C99 标准 (ISO/IEC 9899:1999):
  • 7.3.9.5 creal 函数 (第 180 页)
  • 7.22 泛型数学 <tgmath.h> (第 335-337 页)
  • G.7 泛型数学 <tgmath.h> (第 480 页)

参阅

(C99) (C99) (C99)
计算复数的虚部
(函数)
C++ 文档 关于 real