A complex floating-point type represents a complex number with real and imaginary components based on a corresponding real floating-point type. C groups complex floating-point numbers with unsigned integers, signed integers, and real floating-point numbers as its four principal numeric classes; precision distinguishes the available types. section 5.2 section 5.7.8
Use the standard complex facilities with these constraints:
- Include <complex.h> for full complex-type support, and inspect __STDC_NO_COMPLEX__ because some C platforms do not support complex types. section 5.3.1
- Construct values with CMPLX, CMPLXF, or CMPLXL, or combine floating-point values with the reserved imaginary-unit macro I. section 5.3.1
- Prefer standardized forms such as CMPLX(0.5, 0.5) or 0.5 + 0.5*I; extra-i complex literals such as 0.5i are not standardized. section 5.3.1
- Avoid exact equality comparisons because floating-point operations can lose contributions across very different magnitudes. section 5.7.8
Constructing and inspecting a value
With <complex.h>, CMPLX(0.5, 0.5) creates a double complex value. For a complex value z, creal(z) and cimag(z), supplied through <tgmath.h>, retrieve its real and imaginary parts; mathematically, z == creal(z) + cimag(z)*I. section 5.3.1 section 5.7.8
Table 5.1 Base types according to the four main type classes. Types with a gray background don’t allow for arithmetic; they are promoted before doing arithmetic. Type char is special since it can behave like unsigned or signed, depending on the platform. All types in this table are considered to be distinct types, even if they have the same class and precision.
| Class | Systematic name | Other name | Rank | |
|---|---|---|---|---|
| Integers | Unsigned | bool | _Bool | 0 |
unsigned char | 1 | |||
unsigned short | 2 | |||
unsigned int | unsigned | 3 | ||
unsigned long | 4 | |||
unsigned long long | 5 | |||
| [Un]signed | char | 1 | ||
| Signed | signed char | 1 | ||
signed short | short | 2 | ||
signed int | signed or int | 3 | ||
signed long | long | 4 | ||
signed long long | long long | 5 | ||
| Floating point | Real | float | ||
double | ||||
long double | ||||
| Complex | float _Complex | float complex | ||
double _Complex | double complex | |||
long double _Complex | long double complex | |||
Browse the base-type overview to compare complex floating-point types with C’s other numeric classes and their precision distinctions. section 5.2


