< C Programming

Summary

complex.h is a header file 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>).

Macros

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 Overview

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 (e.g., cabsf and cabsl).

Note that all angles are in radians.

Basic operations
cabscomputes absolute value
cargcomputes argument of a complex number
cimagcomputes imaginary part of a complex number
crealcomputes real part of a complex number
conjcomputes complex conjugate
cprojcomputes complex projection into the Riemann sphere
Exponentiation operations
cexpcomputes complex exponential
clogcomputes complex logarithm
csqrtcomputes complex square root
cpowcomputes complex power
Trigonometric operations
csincomputes complex sine
ccoscomputes complex cosine
ctancomputes complex tangent
casincomputes complex arc sine
cacoscomputes complex arc cosine
catancomputes complex arc tangent
Hyperbolic operations
csinhcomputes complex hyperbolic sine
ccoshcomputes complex hyperbolic cosine
ctanhcomputes complex hyperbolic tangent
casinhcomputes complex hyperbolic arc sine
cacoshcomputes complex hyperbolic arc cosine
catanhcomputes complex hyperbolic arc tangent

References

  1. complex.h: complex arithmetic  Base Definitions Reference, The Single UNIX® Specification, Issue 7 from The Open Group
  2. Dr. Dobb's journal: software tools for the professional programmer, Volume 27 "many results in Annex G are pure invention and mathematically incorrect"
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.