The creal function is part of the <complex.h> header file in C. It is used to return the real part of a complex number of type double. The function takes in a single parameter: a double complex number.
A complex number has a real and an imaginary part.
The illustration below shows how creal works:
The creal function is defined as follows:
double creal(double complex z);
It takes in a single parameter of type double complex.
The following code snippet shows how we can use the creal function. The code below outputs the real part of the complex number:
#include <stdio.h> // Including header file for printf function#include <complex.h> // Including header file for creal functionint main(){double complex z = 1.0 + 3.0*I; // assign value to variableprintf("The real part is %f", creal(z));return 0;}
creal,crealfandcreallare similar functions.
creal takes a double complex number and returns its double realcrealf takes a float complex number and returns itsfloat realcreall takes a long double complex number and returns its long double realFree Resources