Names specified here
Name Description Notes Source Availability
__STDC_IEC_559_COMPLEX__ Indicator of support for IEC 60559-compatible complex arithmetic L ? M Predefined C99 C11
__STDC_NO_COMPLEX__ Indicator for lack of complex arithmetic L ? M Predefined C99 C11
_Complex Type specifier for complex types L ? Q Keyword C99 C11
_Complex_I Square root of −1 ? M <complex.h> C99 C11
carg() Extract complex argument ? (·) <complex.h> C99 C11
carg() Extract complex argument M (·) <tgmath.h> C99 C11
cargf() Extract complex argument ? (·) <complex.h> C99 C11
cargl() Extract complex argument ? (·) <complex.h> C99 C11
cimag() Extract imaginary part of a complex number ? (·) <complex.h> C99 C11
cimag() Extract imaginary part of a complex number M (·) <tgmath.h> C99 C11
cimagf() Extract imaginary part of a complex number ? (·) <complex.h> C99 C11
cimagl() Extract imaginary part of a complex number ? (·) <complex.h> C99 C11
complex Modifier for complex types ? M Q <complex.h> C99 C11
creal() Extract real part of a complex number ? (·) <complex.h> C99 C11
creal() Extract real part of a complex number M (·) <tgmath.h> C99 C11
crealf() Extract real part of a complex number ? (·) <complex.h> C99 C11
creall() Extract real part of a complex number ? (·) <complex.h> C99 C11
I Square root of −1 ? M <complex.h> C99 C11

A complex number is the sum of a real number and an imaginary number. As these two terms cannot be resolved, they can be considered as positions on two orthogonal dimensions, real and imaginary. A complex number is equal to a real number if the imaginary component is zero, and it can be equal to an imaginary number if the real component is zero.

A C implementation may support complex types. The macro __STDC_NO_COMPLEX__ is predefined only if neither are supported, and <complex.h> does not exist.

#if __STDC_VERSION__ >= 199901L && !defined __STDC_NO_COMPLEX__
/* Complex types supported */
#endif

Complex types are indicated by the type specifier _Complex. Here are the standard complex types:

<complex.h> provides types and functions for performing arithmetic on complex numbers, and defines the following macro:

#define complex _Complex

This in turn allows the following names to be used:

It also defines _Complex_I to be a constant expression of type float complex with the value √−1. I is defined to expand either to _Complex_I or _Imaginary_I. A complex constant in general is formed by adding a real constant to a product of a real constant and I:

double complex var = 1.0 + I * 4.0;

To extract the real component of a complex number, use one of the following:

#include <complex.h>
float crealf(float complex);
double creal(double complex);
long double creall(long double complex);
#include <tgmath.h>
real-floating-type creal(complex-type);

To extract the imaginary component of a complex number as a real value, use one of the following:

#include <complex.h>
float cimagf(float complex);
double cimag(double complex);
long double cimagl(long double complex);
#include <tgmath.h>
real-floating-type cimag(complex-type);

You can also get the argument of a complex number, the angle in radians that it subtends with the positive real axis with one of these:

#include <complex.h>
float cargf(float complex);
double carg(double complex);
long double cargl(long double complex);
#include <tgmath.h>
real-floating-type carg(complex-type);

An angle of 90° indicates a positive imaginary number.

The distance from the origin (zero) is given by one of cabs, cabsf and cabsl. <tgmath.h> also defines a type-generic macro fabs.

Also note that each complex type T _Complex is represented as an array of two Ts. This means that you can also safely access the real and imaginary components of an object of complex type directly as reals, for example, with a union:

union {
  double _Complex comb;
  double sep[2];
} u;

Missing

  • __STDC_IEC_559_COMPLEX__

CHaR
Sitemap Supported
Site format updated 2024-06-05T22:37:07.391+0000
Data updated 1970-01-01T00:00:00.000+0000
Page updated 2023-10-04T20:24:03.213+0000