From WikiChip
Difference between revisions of "c/complex.h"
< c

(Created page with "{{C Standard Library}} The '''<complex.h>''' header is part of the standard library of the C programming language which provides a set of macros and functions that sup...")
 
(slight fixes)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{c title|<complex.h> Header}}
 
{{C Standard Library}}
 
{{C Standard Library}}
 
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.
 
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.
  
This header is [[Optional headers - C|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.
+
==Optional Header==
 +
{{C|C11}} has made this header {{C|Optional headers|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.
  
 
<source lang="c">#ifndef __STDC_NO_COMPLEX__
 
<source lang="c">#ifndef __STDC_NO_COMPLEX__
Line 9: Line 11:
 
#    error Implementation has no complex type support!
 
#    error Implementation has no complex type support!
 
#endif</source>
 
#endif</source>
 +
 +
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 ([[IEEE 754|IEC 60559 standard]]).
  
 
== Naming convention ==
 
== Naming convention ==
Line 26: Line 30:
 
! Macro Name !! Description !! Since
 
! Macro Name !! Description !! Since
 
|-
 
|-
| [[Complex.h/complex - C|complex]] || Expands to the _Complex keyword || [[C99]]
+
| {{C|complex.h/complex|complex}} || Expands to the _Complex keyword || [[C99]]
 
|-
 
|-
| [[Complex.h/_Complex_I - C|_Complex_I]] || Expands to the value of the imaginary unit with the type const float _Complex. || [[C99]]
+
| {{C|complex.h/_Complex_I|_Complex_I}} || Expands to the value of the imaginary unit with the type const float _Complex. || [[C99]]
 
|-
 
|-
| [[Complex.h/imaginary - C|imaginary]] || Expands to _Imaginary keyword || [[C99]]
+
| {{C|complex.h/imaginary|imaginary}} || Expands to _Imaginary keyword || [[C99]]
 
|-
 
|-
| [[Complex.h/_Imaginary_I - C|_Imaginary_I]] || Expands to the value of the imaginary unit with the type const float _Imaginary. || [[C99]]
+
| {{C|complex.h/_Imaginary_I|_Imaginary_I}} || Expands to the value of the imaginary unit with the type const float _Imaginary. || [[C99]]
 
|-
 
|-
| [[Complex.h/I - C|I]] || Expands to _Imaginary_I if defined, otherwise expands to _Complex_I || [[C99]]
+
| {{C|complex.h/I|I}} || Expands to _Imaginary_I if defined, otherwise expands to _Complex_I || [[C99]]
 
|-
 
|-
| [[Complex.h/CMPLX - C|CMPLX]] || Expand to an expression of type double complex || [[C11]]
+
| {{C|complex.h/CMPLX|CMPLX}} || Expand to an expression of type double complex || [[C11]]
 
|-
 
|-
| [[Complex.h/CMPLXF - C|CMPLXF]] || Expand to an expression of type float complex || [[C11]]
+
| {{C|complex.h/CMPLXF|CMPLXF}} || Expand to an expression of type float complex || [[C11]]
 
|}
 
|}
  
 
== Pragmas ==
 
== Pragmas ==
The [[algorithms]] used by the functions in this header can be more finely tuned by the following [[Pragmas - C|pragmas]]:
+
The {{C|algorithms|pragmas}}:
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 48: Line 52:
 
! Pragma Name !! Description !! Since
 
! Pragma Name !! Description !! Since
 
|-
 
|-
| [[Complex.h/STDC CX_LIMITED_RANGE - C|STDC CX_LIMITED_RANGE]] || Indicates that the usual mathematical formulas are acceptable. || [[C99]]
+
| {{C|complex.h/STDC|STDC CX_LIMITED_RANGE}} || Indicates that the usual mathematical formulas are acceptable. || [[C99]]
 
|}
 
|}
  
Line 67: Line 71:
 
! Function Prototype !! Description !! Since
 
! Function Prototype !! Description !! Since
 
|-
 
|-
| [[Complex.h/cacos - C|double complex cacos(double complex z);]] || Computes the complex arc cosine of z. || [[C99]]
+
| {{C|complex.h/cacos|double complex cacos(double complex z);}} ||   Computes the complex arc cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cacosf - C|float complex cacosf(float complex z);]] || Computes the complex arc cosine of z. || [[C99]]
+
| {{C|complex.h/cacosf|float complex cacosf(float complex z);}} ||   Computes the complex arc cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cacosl - C|long double complex cacosl(long double complex z);]] || Computes the complex arc cosine of z. || [[C99]]
+
| {{C|complex.h/cacosl|long double complex cacosl(long double complex z);}} ||   Computes the complex arc cosine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/casin - C|double complex casin(double complex z);]] || Computes the complex arc sine of z. || [[C99]]
+
| {{C|complex.h/casin|double complex casin(double complex z);}} || Computes the complex arc sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/casinf - C|float complex casinf(float complex z);]] || Computes the complex arc sine of z. || [[C99]]
+
| {{C|complex.h/casinf|float complex casinf(float complex z);}} || Computes the complex arc sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/casinl - C|long double complex casinl(long double complex z);]] || Computes the complex arc sine of z. || [[C99]]
+
| {{C|complex.h/casinl|long double complex casinl(long double complex z);}} || Computes the complex arc sine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/catan - C|double complex catan(double complex z);]] || Computes the complex arc tangent of z. || [[C99]]
+
| {{C|complex.h/catan|double complex catan(double complex z);}} ||   Computes the complex arc tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/catanf - C|float complex catanf(float complex z);]] || Computes the complex arc tangent of z. || [[C99]]
+
| {{C|complex.h/catanf|float complex catanf(float complex z);}} ||   Computes the complex arc tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/catanl - C|long double complex catanl(long double complex z);]] || Computes the complex arc tangent of z. || [[C99]]
+
| {{C|complex.h/catanl|long double complex catanl(long double complex z);}} ||   Computes the complex arc tangent of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/ccos - C|double complex ccos(double complex z);]] || Computes the complex cosine of z. || [[C99]]
+
| {{C|complex.h/ccos|double complex ccos(double complex z);}} || Computes the complex cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ccosf - C|float complex ccosf(float complex z);]] || Computes the complex cosine of z. || [[C99]]
+
| {{C|complex.h/ccosf|float complex ccosf(float complex z);}} || Computes the complex cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ccosl - C|long double complex ccosl(long double complex z);]] || Computes the complex cosine of z. || [[C99]]
+
| {{C|complex.h/ccosl|long double complex ccosl(long double complex z);}} || Computes the complex cosine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/csin - C|double complex csin(double complex z);]] || Computes the complex sine of z. || [[C99]]
+
| {{C|complex.h/csin|double complex csin(double complex z);}} || Computes the complex sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/csinf - C|float complex csinf(float complex z);]] || Computes the complex sine of z. || [[C99]]
+
| {{C|complex.h/csinf|float complex csinf(float complex z);}} || Computes the complex sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/csinl - C|long double complex csinl(long double complex z);]] || Computes the complex sine of z. || [[C99]]
+
| {{C|complex.h/csinl|long double complex csinl(long double complex z);}} || Computes the complex sine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/ctan - C|double complex ctan(double complex z);]] || Computes the complex tangent of z. || [[C99]]
+
| {{C|complex.h/ctan|double complex ctan(double complex z);}} || Computes the complex tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ctanf - C|float complex ctanf(float complex z);]] || Computes the complex tangent of z. || [[C99]]
+
| {{C|complex.h/ctanf|float complex ctanf(float complex z);}} || Computes the complex tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ctanl - C|long double complex ctanl(long double complex z);]] || Computes the complex tangent of z. || [[C99]]
+
| {{C|complex.h/ctanl|long double complex ctanl(long double complex z);}} || Computes the complex tangent of z. || [[C99]]
 
|}
 
|}
  
Line 121: Line 125:
 
! Function Prototype !! Description !! Since
 
! Function Prototype !! Description !! Since
 
|-
 
|-
| [[Complex.h/cacosh - C|double complex cacosh(double complex z);]] || Computes the complex arc hyperbolic cosine of z. || [[C99]]
+
| {{C|complex.h/cacosh|double complex cacosh(double complex z);}} || Computes the complex arc hyperbolic cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cacoshf - C|float complex cacoshf(float complex z);]] || Computes the complex arc hyperbolic cosine of z. || [[C99]]
+
| {{C|complex.h/cacoshf|float complex cacoshf(float complex z);}} || Computes the complex arc hyperbolic cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cacoshl - C|long double complex cacoshl(long double complex z);]] || Computes the complex arc hyperbolic cosine of z. || [[C99]]
+
| {{C|complex.h/cacoshl|long double complex cacoshl(long double complex z);}} || Computes the complex arc hyperbolic cosine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/casinh - C|double complex casinh(double complex z);]] || Computes the complex arc hyperbolic sine of z. || [[C99]]
+
| {{C|complex.h/casinh|double complex casinh(double complex z);}} || Computes the complex arc hyperbolic sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/casinhf - C|float complex casinhf(float complex z)]] || Computes the complex arc hyperbolic sine of z. || [[C99]]
+
| {{C|complex.h/casinhf|float complex casinhf(float complex z)}} || Computes the complex arc hyperbolic sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/casinhl - C|long double complex casinhl(long double complex z);]] || Computes the complex arc hyperbolic sine of z. || [[C99]]
+
| {{C|complex.h/casinhl|long double complex casinhl(long double complex z);}} || Computes the complex arc hyperbolic sine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/catanh - C|double complex catanh(double complex z);]] || Computes the complex arc hyperbolic tangent of z. || [[C99]]
+
| {{C|complex.h/catanh|double complex catanh(double complex z);}} || Computes the complex arc hyperbolic tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/catanhf - C|float complex catanhf(float complex z);]] || Computes the complex arc hyperbolic tangent of z. || [[C99]]
+
| {{C|complex.h/catanhf|float complex catanhf(float complex z);}} || Computes the complex arc hyperbolic tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/catanhl - C|long double complex catanhl(long double complex z);]] || Computes the complex arc hyperbolic tangent of z. || [[C99]]
+
| {{C|complex.h/catanhl|long double complex catanhl(long double complex z);}} || Computes the complex arc hyperbolic tangent of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/ccosh - C|double complex ccosh(double complex z);]] || Computes the complex hyperbolic cosine of z. || [[C99]]
+
| {{C|complex.h/ccosh|double complex ccosh(double complex z);}} || Computes the complex hyperbolic cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ccoshf - C|float complex ccoshf(float complex z);]] || Computes the complex hyperbolic cosine of z. || [[C99]]
+
| {{C|complex.h/ccoshf|float complex ccoshf(float complex z);}} || Computes the complex hyperbolic cosine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ccoshl - C|long double complex ccoshl(long double complex z);]] || Computes the complex hyperbolic cosine of z. || [[C99]]
+
| {{C|complex.h/ccoshl|long double complex ccoshl(long double complex z);}} || Computes the complex hyperbolic cosine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/csinh - C|double complex csinh(double complex z);]] || Computes the complex hyperbolic sine of z. || [[C99]]
+
| {{C|complex.h/csinh|double complex csinh(double complex z);}} || Computes the complex hyperbolic sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/csinhf - C|float complex csinhf(float complex z);]] || Computes the complex hyperbolic sine of z. || [[C99]]
+
| {{C|complex.h/csinhf|float complex csinhf(float complex z);}} || Computes the complex hyperbolic sine of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/csinhl - C|long double complex csinhl(long double complex z);]] || Computes the complex hyperbolic sine of z. || [[C99]]
+
| {{C|complex.h/csinhl|long double complex csinhl(long double complex z);}} || Computes the complex hyperbolic sine of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/ctanh - C|double complex ctanh(double complex z);]] || Computes the complex hyperbolic tangent of z. || [[C99]]
+
| {{C|complex.h/ctanh|double complex ctanh(double complex z);}} || Computes the complex hyperbolic tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ctanhf - C|float complex ctanhf(float complex z);]] || Computes the complex hyperbolic tangent of z. || [[C99]]
+
| {{C|complex.h/ctanhf|float complex ctanhf(float complex z);}} || Computes the complex hyperbolic tangent of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/ctanhl - C|long double complex ctanhl(long double complex z);]] || Computes the complex hyperbolic tangent of z. || [[C99]]
+
| {{C|complex.h/ctanhl|long double complex ctanhl(long double complex z);}} || Computes the complex hyperbolic tangent of z. || [[C99]]
 
|}
 
|}
  
Line 175: Line 179:
 
! Function Prototype !! Description !! Since
 
! Function Prototype !! Description !! Since
 
|-
 
|-
| [[Complex.h/cexp - C|double complex cexp(double complex z);]] || Computes the complex base-e exponential of z. || [[C99]]
+
| {{C|complex.h/cexp|double complex cexp(double complex z);}} || Computes the complex base-e exponential of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cexpf - C|float complex cexpf(float complex z);]] || Computes the complex base-e exponential of z. || [[C99]]
+
| {{C|complex.h/cexpf|float complex cexpf(float complex z);}} || Computes the complex base-e exponential of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cexpl - C|long double complex cexpl(long double complex z);]] || Computes the complex base-e exponential of z. || [[C99]]
+
| {{C|complex.h/cexpl|long double complex cexpl(long double complex z);}} || Computes the complex base-e exponential of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/clog - C|double complex clog(double complex z);]] || Computes the complex natural (base-e) logarithm of z. || [[C99]]
+
| {{C|complex.h/clog|double complex clog(double complex z);}} || Computes the complex natural (base-e) logarithm of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/clogf - C|float complex clogf(float complex z);]] || Computes the complex natural (base-e) logarithm of z. || [[C99]]
+
| {{C|complex.h/clogf|float complex clogf(float complex z);}} || Computes the complex natural (base-e) logarithm of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/clogl - C|long double complex clogl(long double complex z);]] || Computes the complex natural (base-e) logarithm of z. || [[C99]]
+
| {{C|complex.h/clogl|long double complex clogl(long double complex z);}} || Computes the complex natural (base-e) logarithm of z. || [[C99]]
 
|}
 
|}
  
Line 197: Line 201:
 
! Function Prototype !! Description !! Since
 
! Function Prototype !! Description !! Since
 
|-
 
|-
| [[Complex.h/cabs - C|double cabs(double complex z);]] || Computes the complex absolute value of z. || [[C99]]
+
| {{C|complex.h/cabs|double cabs(double complex z);}} || Computes the complex absolute value of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cabsf - C|float cabsf(float complex z);]] || Computes the complex absolute value of z. || [[C99]]
+
| {{C|complex.h/cabsf|float cabsf(float complex z);}} || Computes the complex absolute value of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cabsl - C|long double cabsl(long double complex z);]] || Computes the complex absolute value of z. || [[C99]]
+
| {{C|complex.h/cabsl|long double cabsl(long double complex z);}} || Computes the complex absolute value of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/cpow - C|double complex cpow(double complex x, double complex y);]] || Computes the complex power function x<sup>y</sup>. || [[C99]]
+
| {{C|complex.h/cpow|double complex cpow(double complex x, double complex y);}} || Computes the complex power function x<sup>y</sup>. || [[C99]]
 
|-
 
|-
| [[Complex.h/cpowf - C|float complex cpowf(float complex x, float complex y);]] || Computes the complex power function x<sup>y</sup>. || [[C99]]
+
| {{C|complex.h/cpowf|float complex cpowf(float complex x, float complex y);}} || Computes the complex power function x<sup>y</sup>. || [[C99]]
 
|-
 
|-
| [[Complex.h/cpowl - C|long double complex cpowl(long double complex x, long double complex y);]] || Computes the complex power function x<sup>y</sup>. || [[C99]]
+
| {{C|complex.h/cpowl|long double complex cpowl(long double complex x, long double complex y);}} || Computes the complex power function x<sup>y</sup>. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/csqrt - C|double complex csqrt(double complex z);]] || Computes the complex square root of z. || [[C99]]
+
| {{C|complex.h/csqrt|double complex csqrt(double complex z);}} || Computes the complex square root of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/csqrtf - C|float complex csqrtf(float complex z);]] || Computes the complex square root of z. || [[C99]]
+
| {{C|complex.h/csqrtf|float complex csqrtf(float complex z);}} || Computes the complex square root of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/csqrtl - C|long double complex csqrtl(long double complex z);]] || Computes the complex square root of z. || [[C99]]
+
| {{C|complex.h/csqrtl|long double complex csqrtl(long double complex z);}} || Computes the complex square root of z. || [[C99]]
 
|}
 
|}
  
Line 227: Line 231:
 
! Function Prototype !! Description !! Since
 
! Function Prototype !! Description !! Since
 
|-
 
|-
| [[Complex.h/carg - C|double carg(double complex z);]] || Computes the phase angle of z. || [[C99]]
+
| {{C|complex.h/carg|double carg(double complex z);}} || Computes the phase angle of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cargf - C|float cargf(float complex z);]] || Computes the phase angle of z. || [[C99]]
+
| {{C|complex.h/cargf|float cargf(float complex z);}} || Computes the phase angle of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cargl - C|long double cargl(long double complex z);]] || Computes the phase angle of z. || [[C99]]
+
| {{C|complex.h/cargl|long double cargl(long double complex z);}} || Computes the phase angle of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/cimag - C|double cimag(double complex z);]] || Computes the imaginary part of z. || [[C99]]
+
| {{C|complex.h/cimag|double cimag(double complex z);}} || Computes the imaginary part of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cimagf - C|float cimagf(float complex z);]] || Computes the imaginary part of z. || [[C99]]
+
| {{C|complex.h/cimagf|float cimagf(float complex z);}} || Computes the imaginary part of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/cimagl - C|long double cimagl(long double complex z);]] || Computes the imaginary part of z. || [[C99]]
+
| {{C|complex.h/cimagl|long double cimagl(long double complex z);}} || Computes the imaginary part of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/conj - C|double complex conj(double complex z);]] || Computes the complex conjugate of z. || [[C99]]
+
| {{C|complex.h/conj|double complex conj(double complex z);}} || Computes the complex conjugate of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/conjf - C|float complex conjf(float complex z);]] || Computes the complex conjugate of z. || [[C99]]
+
| {{C|complex.h/conjf|float complex conjf(float complex z);}} || Computes the complex conjugate of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/conjl - C|long double complex conjl(long double complex z);]] || Computes the complex conjugate of z. || [[C99]]
+
| {{C|complex.h/conjl|long double complex conjl(long double complex z);}} || Computes the complex conjugate of z. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/cproj - C|double complex cproj(double complex z);]] || Computes a projection of z onto the Riemann sphere. || [[C99]]
+
| {{C|complex.h/cproj|double complex cproj(double complex z);}} || Computes a projection of z onto the Riemann sphere. || [[C99]]
 
|-
 
|-
| [[Complex.h/cprojf - C|float complex cprojf(float complex z);]] || Computes a projection of z onto the Riemann sphere. || [[C99]]
+
| {{C|complex.h/cprojf|float complex cprojf(float complex z);}} || Computes a projection of z onto the Riemann sphere. || [[C99]]
 
|-
 
|-
| [[Complex.h/cprojl - C|long double complex cprojl(long double complex z);]] || Computes a projection of z onto the Riemann sphere. || [[C99]]
+
| {{C|complex.h/cprojl|long double complex cprojl(long double complex z);}} || Computes a projection of z onto the Riemann sphere. || [[C99]]
 
|-
 
|-
 
| &nbsp; || &nbsp; ||
 
| &nbsp; || &nbsp; ||
 
|-
 
|-
| [[Complex.h/creal - C|double creal(double complex z);]] || The creal functions compute the real part of z. || [[C99]]
+
| {{C|complex.h/creal|double creal(double complex z);}} || The creal functions compute the real part of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/crealf - C|float crealf(float complex z);]] || The creal functions compute the real part of z. || [[C99]]
+
| {{C|complex.h/crealf|float crealf(float complex z);}} || The creal functions compute the real part of z. || [[C99]]
 
|-
 
|-
| [[Complex.h/creall - C|long double creall(long double complex z);]] || The creal functions compute the real part of z. || [[C99]]
+
| {{C|complex.h/creall|long double creall(long double complex z);}} || The creal functions compute the real part of z. || [[C99]]
 
|}
 
|}
  
{{DEFAULTSORT:Complex.h - C}}
+
{{DEFAULTSORT:complex.h}}
[[Category:C standard library]]
+
[[Category:complex.h]]
[[Category:Complex.h - C]]
 

Latest revision as of 19:46, 7 January 2015

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