Name

cimag

Synopsis

Obtains the imaginary part of a complex number

#include <complex.h>
doublecimag( double complex z );
float cimagf( float complex z );
long double cimagl( long double complex z );

A complex number is represented as two floating-point numbers, one quantifying the real part and one quantifying the imaginary part. The cimag() function returns the floating-point number that represents the imaginary part of the complex argument.

Example

double complex z = 4.5 − 6.7 * I;

printf( "The complex variable z is equal to %.2f %+.2f \xD7 I.\n",
        creal(z),cimag(z) );

This code produces the following output:

The complex variable z is equal to 4.50 -6.70 × I.

Get C in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.