From WikiChip
<complex.h> Header - C
< c

The <complex.h> header is part of the standard library of the C programming language which provides a set of macros and functions that support complex arithmetic.

Optional Header[edit]

C11 has made this header optional and therefore need not be provided by an implementation. A program can check for the existence of this header by checking if the macro __STDC_NO_COMPLEX__ is defined. When defined, an implementation is not required to provide this header nor any of its facilities.

#ifndef __STDC_NO_COMPLEX__
#    include <complex.h>
#else
#    error Implementation has no complex type support!
#endif

If the implementation defines __STDC_IEC_559_COMPLEX__ to the integer constant 1, the complex arithmetic implementation conforms to Annex G of the C standard (IEC 60559 standard).

Naming convention[edit]

The naming convention used in this header is a set of principle functions followed by a number of secondary functions of the same name but with a f and l suffixes for the float and long double versions of the function. The principle function is one with one or more double complex parameters an a double complex or double return value.

Values in radians[edit]

All the functions in this header expect values in radians, not degrees.

Imaginary unit[edit]

The imaginary unit number, commonly denoted as i, is defined as a number i such that i2 = -1.

Macros[edit]

The header provides the following macro definitions:

Macro Name Description Since
complex Expands to the _Complex keyword C99
_Complex_I Expands to the value of the imaginary unit with the type const float _Complex. C99
imaginary Expands to _Imaginary keyword C99
_Imaginary_I Expands to the value of the imaginary unit with the type const float _Imaginary. C99
I Expands to _Imaginary_I if defined, otherwise expands to _Complex_I C99
CMPLX Expand to an expression of type double complex C11
CMPLXF Expand to an expression of type float complex C11

Pragmas[edit]

The pragmas:

Pragma Name Description Since
STDC CX_LIMITED_RANGE Indicates that the usual mathematical formulas are acceptable. C99

Functions[edit]

The <complex.h> header provides functions that fall under five distinct categories:

Trigonometric functions[edit]

This category provides a set of the basic trigonometric functions such as cosine, sine, and tangent as well as arc cosine, arc sine, and arc tangent for operating on complex numbers.

Function Prototype Description Since
double complex cacos(double complex z); Computes the complex arc cosine of z. C99
float complex cacosf(float complex z); Computes the complex arc cosine of z. C99
long double complex cacosl(long double complex z); Computes the complex arc cosine of z. C99
   
double complex casin(double complex z); Computes the complex arc sine of z. C99
float complex casinf(float complex z); Computes the complex arc sine of z. C99
long double complex casinl(long double complex z); Computes the complex arc sine of z. C99
   
double complex catan(double complex z); Computes the complex arc tangent of z. C99
float complex catanf(float complex z); Computes the complex arc tangent of z. C99
long double complex catanl(long double complex z); Computes the complex arc tangent of z. C99
   
double complex ccos(double complex z); Computes the complex cosine of z. C99
float complex ccosf(float complex z); Computes the complex cosine of z. C99
long double complex ccosl(long double complex z); Computes the complex cosine of z. C99
   
double complex csin(double complex z); Computes the complex sine of z. C99
float complex csinf(float complex z); Computes the complex sine of z. C99
long double complex csinl(long double complex z); Computes the complex sine of z. C99
   
double complex ctan(double complex z); Computes the complex tangent of z. C99
float complex ctanf(float complex z); Computes the complex tangent of z. C99
long double complex ctanl(long double complex z); Computes the complex tangent of z. C99

Hyperbolic functions[edit]

This category includes a set of functions for computing the hyperbolic cosine, sine, and tangent of complex numbers as well as the arc hyperbolic cosine, sine, and tangent of complex numbers.

Function Prototype Description Since
double complex cacosh(double complex z); Computes the complex arc hyperbolic cosine of z. C99
float complex cacoshf(float complex z); Computes the complex arc hyperbolic cosine of z. C99
long double complex cacoshl(long double complex z); Computes the complex arc hyperbolic cosine of z. C99
   
double complex casinh(double complex z); Computes the complex arc hyperbolic sine of z. C99
float complex casinhf(float complex z) Computes the complex arc hyperbolic sine of z. C99
long double complex casinhl(long double complex z); Computes the complex arc hyperbolic sine of z. C99
   
double complex catanh(double complex z); Computes the complex arc hyperbolic tangent of z. C99
float complex catanhf(float complex z); Computes the complex arc hyperbolic tangent of z. C99
long double complex catanhl(long double complex z); Computes the complex arc hyperbolic tangent of z. C99
   
double complex ccosh(double complex z); Computes the complex hyperbolic cosine of z. C99
float complex ccoshf(float complex z); Computes the complex hyperbolic cosine of z. C99
long double complex ccoshl(long double complex z); Computes the complex hyperbolic cosine of z. C99
   
double complex csinh(double complex z); Computes the complex hyperbolic sine of z. C99
float complex csinhf(float complex z); Computes the complex hyperbolic sine of z. C99
long double complex csinhl(long double complex z); Computes the complex hyperbolic sine of z. C99
   
double complex ctanh(double complex z); Computes the complex hyperbolic tangent of z. C99
float complex ctanhf(float complex z); Computes the complex hyperbolic tangent of z. C99
long double complex ctanhl(long double complex z); Computes the complex hyperbolic tangent of z. C99

Exponential and logarithmic functions[edit]

Below are a set of functions for computing the base-e exponent or logarithm of a complex number.

Function Prototype Description Since
double complex cexp(double complex z); Computes the complex base-e exponential of z. C99
float complex cexpf(float complex z); Computes the complex base-e exponential of z. C99
long double complex cexpl(long double complex z); Computes the complex base-e exponential of z. C99
   
double complex clog(double complex z); Computes the complex natural (base-e) logarithm of z. C99
float complex clogf(float complex z); Computes the complex natural (base-e) logarithm of z. C99
long double complex clogl(long double complex z); Computes the complex natural (base-e) logarithm of z. C99

Power and absolute-value functions[edit]

This category provides functions that can calculate the the absolute value, power, and square root of complex numbers.

Function Prototype Description Since
double cabs(double complex z); Computes the complex absolute value of z. C99
float cabsf(float complex z); Computes the complex absolute value of z. C99
long double cabsl(long double complex z); Computes the complex absolute value of z. C99
   
double complex cpow(double complex x, double complex y); Computes the complex power function xy. C99
float complex cpowf(float complex x, float complex y); Computes the complex power function xy. C99
long double complex cpowl(long double complex x, long double complex y); Computes the complex power function xy. C99
   
double complex csqrt(double complex z); Computes the complex square root of z. C99
float complex csqrtf(float complex z); Computes the complex square root of z. C99
long double complex csqrtl(long double complex z); Computes the complex square root of z. C99

Manipulation functions[edit]

The manipulation functions provide a way of accessing the imaginary or real part of a complex number as well as computing its projection and conjugate.

Function Prototype Description Since
double carg(double complex z); Computes the phase angle of z. C99
float cargf(float complex z); Computes the phase angle of z. C99
long double cargl(long double complex z); Computes the phase angle of z. C99
   
double cimag(double complex z); Computes the imaginary part of z. C99
float cimagf(float complex z); Computes the imaginary part of z. C99
long double cimagl(long double complex z); Computes the imaginary part of z. C99
   
double complex conj(double complex z); Computes the complex conjugate of z. C99
float complex conjf(float complex z); Computes the complex conjugate of z. C99
long double complex conjl(long double complex z); Computes the complex conjugate of z. C99
   
double complex cproj(double complex z); Computes a projection of z onto the Riemann sphere. C99
float complex cprojf(float complex z); Computes a projection of z onto the Riemann sphere. C99
long double complex cprojl(long double complex z); Computes a projection of z onto the Riemann sphere. C99
   
double creal(double complex z); The creal functions compute the real part of z. C99
float crealf(float complex z); The creal functions compute the real part of z. C99
long double creall(long double complex z); The creal functions compute the real part of z. C99