complex.h is a header file in the standard library of the C programming language that defines functionality for complex arithmetic.[1] These functions use the built-in type complex
which was introduced with the C99 revision of C.
This header should not be confused with the C++ standard library header <complex>
, which implements complex numbers in a completely different way (as a template class, complex<T>
).
Macro
Universal macro:
- complex - alias of _Complex
- _Complex_I - constant, which has type "const float _Complex" and value of imaginary unit I, I*I=-1
Defined only for `C99 Annex G`-compatible compiler modes - native support of imaginary types (it is very rare because Annex G is mathematically incorrect[2]):
- imaginary - alias of _Imaginary
- _Imaginary_I Expands to a constant expression of type const float _Imaginary with the value of the imaginary unit.
Universal alias of I:
- I - alias of _Imaginary_I if it is defined else - alias of _Complex_I
Application may undefine complex, imaginary, and I macros if they interfere with internal values.
Functions
Each function declared in complex.h
has three versions, each of which works with a different floating-point type (double
, float
and long double
). Only the double
version of each function is listed here; to use the float
(or long double
) version, append an f
(or an l
, respectively) to the function's name.
Note that all angles are in radians.
double cabs(double complex);
Absolute value
double complex cacos(double complex);
Complex inverse cosine
double complex cacosh(double complex);
Complex inverse hyperbolic cosine
double carg(double complex);
Complex argument
double complex casin(double complex);
Complex inverse sine
double complex casinh(double complex);
Complex inverse hyperbolic sine
double complex catan(double complex);
Complex inverse tangent
double complex catanh(double complex);
Complex inverse hyperbolic tangent
double complex ccos(double complex);
Complex cosine
double complex ccosh(double complex);
Complex hyperbolic cosine
double complex cexp(double complex);
Complex exponential
double cimag(double complex);
Imaginary part of complex number
double complex clog(double complex);
Complex logarithm
double complex conj(double complex);
Complex conjugate
double complex cpow(double complex, double complex);
Complex power
double complex cproj(double complex);
Complex projection[A]
double creal(double complex);
Real part of complex number
double complex csin(double complex);
Complex sine
double complex csinh(double complex);
Complex hyperbolic sine
double complex csqrt(double complex);
Complex square root
double complex ctan(double complex);
Complex tangent
double complex ctanh(double complex);
Complex hyperbolic tangent
- A cproj(z) projects the complex number z onto the Riemann sphere; the result is z itself, except complex infinities are mapped to positive infinity on the real axis.[3]
References
- ^ The Single UNIX Specification, Version 5 from The Open Group
: complex arithmetic – Base Definitions Reference,
- ^ Dr. Dobb's journal: software tools for the professional programmer, Volume 27 "many results in Annex G are pure invention and mathematically incorrect"
- ^ The Single UNIX Specification, Version 5 from The Open Group
: complex projection function – System Interfaces Reference,