The complex.h header in the C programming language is part of the C standard library. It was officially introduced with the C99 standard and provides support for complex arithmetic operations. This header file defines macros, constants, and functions to handle complex numbers, which are essential for applications in fields like signal processing, control systems, electromagnetism, and quantum mechanics where the concept of imaginary numbers is crucial.
float _Complex
(or simply float complex
)double _Complex
(or double complex
)long double _Complex
(or long double complex
)complex
and I
for creating complex numbers._Complex_I
and _Complex_I
for compatibility with older C standards.creal(), cimag()
to get the real and imaginary parts of a complex number.cabs(), carg()
for magnitude and argument.cexp(), clog()
for exponential and logarithmic functions.
#include <complex.h>
#include <stdio.h>
int main() {
double complex z = 3.0 + 4.0 * I;
printf("The complex number z is %f + %f i\n", creal(z), cimag(z));
double complex result = cexp(z);
printf("e^z is %f + %f i\n", creal(result), cimag(result));
return 0;
}