![The C Standard Library Reference](/c_standard_library/images/c-mini-logo.jpg)
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C library - cexp() function
The C complex library cexp() function is used to calculate the complex base-e exponential of the given z(complex number).
This function is depends on the type of z(complex number). If the z is of the "float" type, we can use cexpf() to compute complex base-e exponential, For type long double, use cexpl(), and for type double, use cexp().
Note: The complex exponential function ez for z = a+bi equals ea cis(b), where cis(b) is cos(b) + isin(b). The exponential function is an entire function in the complex plane and has no branch cuts.
Syntax
Following is the C library syntax of cexp() function −
double complex cexp( double complex z );
Parameters
This function accepts a single parameter −
-
Z − It represent a complex number for which we want to compute the exponential.
Return Value
This function returns, e raised to the power of z (ez) if no errors occur. where e represent the base of the natural logarithm.
Example 1
Following is the basic c program to demonstrate the use of cexp() of a complex number.
#include <stdio.h> #include <complex.h> #include <math.h> int main() { double complex z = 1 + 2*I; double expo = cexp(z); printf("z = %.1f + %.1fi\n", creal(z),cimag(z)); printf("exponent of z = %.1f + %.1fi\n", creal(expo),cimag(expo)); }
Output
Following is the output −
z = 1.0 + 2.0i exponent of z = -1.1 + 0.0i
Example 2
Calculate the value of eiπ
Let's see another example, we use of Euler's formula to calculate the exponential of a complex number using the cexp() function.
#include <stdio.h> #include <math.h> #include <complex.h> int main(void) { double PI = acos(-1); double complex z = cexp(I * PI); // Euler's formula printf("exp(i*pi) = %.1f%+.1fi\n", creal(z), cimag(z)); }
Output
Following is the output −
exp(i*pi) = -1.0+0.0i
Example 3
Exponent of -ve complex number
The below c example, we calculate the e-3 + -4i using the cexp() function.
#include <stdio.h> #include <complex.h> #include <math.h> int main() { double complex z = -3 + -4*I; double expo = cexp(z); printf("z = %.1f + %.1fi\n", creal(z),cimag(z)); printf("exponent of z = %.1f + %.1fi\n", creal(expo),cimag(expo)); }
Output
Following is the output −
z = -3.0 + -4.0i exponent of z = -0.0 + 0.0i