##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Complex number arithmetic

From cppreference.com
< c‎ | numeric

The header `<complex.h>` defines macros and declares functions that support complex number arithmetic. Complex values are values of type `double complex`, `float complex`, `long double complex`,

If the macro constant `__STDC_IEC_559_COMPLEX__`(C99) is defined by the compiler, in addition to the complex types, the imaginary types are also supported: `double imaginary`, `float imaginary`, and `long double imaginary`. When a value of imaginary type is converted to a value of complex type, the resulting complex type has its real component set to zero. When a value of complex type is converted to a value of imaginary type, the real component is discarded.

Standard arithmetic operators +, -, *, / can be used with real, complex, and imaginary types in any combination.

If the macro constant `__STDC_NO_COMPLEX__`(C11) is defined by the compiler, the header `<complex.h>` and all of the names listed here are not provided.

If #pragma STDC CX_LIMITED_RANGE on is used, complex multiplication, division, and absolute value may use simplified mathematical formulas, despite the possibility of intermediate overflow.

Defined in header `<complex.h>`
##### Types
complex (C99) | complex type macro (macro constant) [edit]
Complex_I (C99) | the complex unit constant i (macro constant) [edit]
##### The imaginary constant
imaginary (C99) | imaginary type macro (macro constant) [edit]
Imaginary_I (C99) | the imaginary unit constant i (macro constant) [edit]
I (C99) | the complex or imaginary unit constant i (macro constant) [edit]
##### Manipulation
CMPLX CMPLXF CMPLXL (C11)(C11)(C11) | constructs a complex number from real and imaginary parts (function macro) [edit]
cimag cimagf cimagl (C99)(C99)(C99) | computes the imaginary part a complex number (function) [edit]
creal crealf creall (C99)(C99)(C99) | computes the real part of a complex number (function) [edit]
carg cargf cargl (C99)(C99)(C99) | computes the phase angle of a complex number (function) [edit]
conj conjf conjl (C99)(C99)(C99) | computes the complex conjugate (function) [edit]
cproj cprojf cprojl (C99)(C99)(C99) | computes the projection on Riemann sphere (function) [edit]
cabs cabsf cabsl (C99)(C99)(C99) | computes the magnitude of a complex number (function) [edit]
##### Exponential functinos
cexp cexpf cexpl (C99)(C99)(C99) | computes the complex base-e exponential (function) [edit]
clog clogf clogl (C99)(C99)(C99) | computes the complex natural logarithm (function) [edit]
##### Power functions
cpow cpowf cpowl (C99)(C99)(C99) | computes the complex power function (function) [edit]
csqrt csqrtf csqrtl (C99)(C99)(C99) | computes the complex square root (function) [edit]
##### Trigonometric functions
cacos cacosf cacosl (C99)(C99)(C99) | computes the complex arc cosine (function) [edit]
casin casinf casinl (C99)(C99)(C99) | computes the complex arc sine (function) [edit]
catan catanf catanl (C99)(C99)(C99) | computes the complex arc tangent (function) [edit]
ccos ccosf ccosl (C99)(C99)(C99) | computes the complex cosine (function) [edit]
csin csinf csinl (C99)(C99)(C99) | computes the complex sine (function) [edit]
ctan ctanf ctanl (C99)(C99)(C99) | computes the complex tangent (function) [edit]
##### Hyperbolic functions
cacosh cacoshf cacoshl (C99)(C99)(C99) | computes the complex arc hyperbolic cosine (function) [edit]
casinh casinhf casinhl (C99)(C99)(C99) | computes the complex arc hyperbolic sine (function) [edit]
catanh catanhf catanhl (C99)(C99)(C99) | computes the complex arc hyperbolic tangent (function) [edit]
ccosh ccoshf ccoshl (C99)(C99)(C99) | computes the complex hyperbolic cosine (function) [edit]
csinh csinhf csinhl (C99)(C99)(C99) | computes the complex hyperbolic sine (function) [edit]
ctanh ctanhf ctanhl (C99)(C99)(C99) | computes the complex hyperbolic tangent (function) [edit]

### [edit] Example

Run this code

    #include <stdio.h>        /* printf()                       */
    #include <complex.h>      /* complex, float complex, I, ... */

    int main () {

        #ifdef __STDC_IEC_559_COMPLEX__
               printf("_STDC_IEC_559_COMPLEX__ defined\n");
        #else
               printf("_STDC_IEC_559_COMPLEX__ not defined\n");
        #endif
        #ifdef __STDC_NO_COMPLEX__
               printf("__STDC_NO_COMPLEX__ defined\n");
        #else
               printf("__STDC_NO_COMPLEX__ not defined\n");
        #endif
        printf("\n");

        printf("%2zu\n", sizeof(float complex));           /*  8 */
        printf("%2zu\n", sizeof(double complex));          /* 16 */
        printf("%2zu\n", sizeof(long double complex));     /* implementation-defined */
        return 0;
    }

Output:

    _STDC_IEC_559_COMPLEX__ defined
    __STDC_NO_COMPLEX__ not defined

     8
    16
    32

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=c/numeric/complex&oldid=67389"