Rate This Document
Findability
Accuracy
Completeness
Readability

cimag

Return the imaginary part of a complex number.

Interface Definition

C interface:

float cimagf(float complex x);

double cimag(double complex x);

Parameters

Parameter

Type

Description

Input/Output

x

  • For cimagf, x is of complex single-precision floating-point type.
  • For cimag, x is of complex double-precision floating-point type.

Floating-point value of the input data.

Input

Return Value

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

Dependency

C: "kc.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(" * cimag(%.2f + %.2f*I) = %.6f\n", x1, y1, cimag(__builtin_complex(x1, y1)));
    printf(" * cimag(%.2f + %.2f*I) = %.6f\n", x2, y2, cimag(__builtin_complex(x2, y2)));
    printf(" * cimag(%.2f + %.2f*I) = %.6f\n", x3, y3, cimag(__builtin_complex(x3, y3)));
    printf(" * cimag(%.2f + %.2f*I) = %.6f\n", x4, y4, cimag(__builtin_complex(x4, y4)));
    printf(" * cimag(%.2f + %.2f*I) = %.6f\n", x5, y5, cimag(__builtin_complex(x5, y5)));
    printf(" **/\n");
 
   /*
    * cimag(inf + inf*I) = inf
    * cimag(2.00 + 3.00*I) = 3.000000
    * cimag(-2.50 + -3.40*I) = -3.400000
    * cimag(nan + nan*I) = nan
    * cimag(0.00 + 0.00*I) = 0.000000
    **/