Rate This Document
Findability
Accuracy
Completeness
Readability

creal

Return the real part of a complex number.

Interface Definition

C interface:

float crealf(float complex x);

double creal(double complex x);

long double creal(long double complex x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For crealf, x is of complex single-precision floating-point type.
  • For creal, x is of complex double-precision floating-point type.
  • For creall, x is of complex, long, double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

The real part y of x is returned. y ∈ (–INF, +INF)

Dependency

C: "km.h"

Example

C interface:
    // typical usage
    double x1 = INFINITY, y1 = INFINITY;
    double x2 = 2.0, y2 = 3.0;
    double x3 = -2.5, y3 = -3.4;
    double x4 = NAN, y4 = NAN;
    double x5 = 0, y5 = 0;
    // print result
    printf("/*\n");
    printf(" * creal(%.2f + %.2f*I) = %.6f\n", x1, y1, creal(__builtin_complex(x1, y1)));
    printf(" * creal(%.2f + %.2f*I) = %.6f\n", x2, y2, creal(__builtin_complex(x2, y2)));
    printf(" * creal(%.2f + %.2f*I) = %.6f\n", x3, y3, creal(__builtin_complex(x3, y3)));
    printf(" * creal(%.2f + %.2f*I) = %.6f\n", x4, y4, creal(__builtin_complex(x4, y4)));
    printf(" * creal(%.2f + %.2f*I) = %.6f\n", x5, y5, creal(__builtin_complex(x5, y5)));
    printf(" **/\n");

   /*
    * creal(inf + inf*I) = inf
    * creal(2.00 + 3.00*I) = 2.000000
    * creal(-2.50 + -3.40*I) = -2.500000
    * creal(nan + nan*I) = nan
    * creal(0.00 + 0.00*I) = 0.000000
    **/