You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describes C-language complex math support in the Microsoft C runtime library (CRT)
ms.date
05/14/2019
f1_keywords
c.complex
helpviewer_keywords
complex numbers, math routines
math routines
complex numbers
C complex math support
The Microsoft C Runtime library (CRT) provides complex math library functions, including all of the ones required by ISO C99. The compiler doesn't directly support a complex or _Complex keyword, therefore the Microsoft implementation uses structure types to represent complex numbers.
These functions are implemented to balance performance with correctness. Because producing the correctly rounded result may be prohibitively expensive, these functions are designed to efficiently produce a close approximation to the correctly rounded result. In most cases, the result produced is within +/-1 unit of least precision (ULP) of the correctly rounded result, though there may be cases where there's greater inaccuracy.
The complex math routines rely on the floating point math library functions for their implementation. These functions have different implementations for different CPU architectures. For example, the 32-bit x86 CRT may have a different implementation than the 64-bit x64 CRT. In addition, some of the functions may have multiple implementations for a given CPU architecture. The most efficient implementation is selected dynamically at run-time depending on the instruction sets supported by the CPU. For example, in the 32-bit x86 CRT, some functions have both an x87 implementation and an SSE2 implementation. When running on a CPU that supports SSE2, the faster SSE2 implementation is used. When running on a CPU that doesn't support SSE2, the slower x87 implementation is used. Because different implementations of the math library functions may use different CPU instructions and different algorithms to produce their results, the functions may produce different results across CPUs. In most cases, the results are within +/-1 ULP of the correctly rounded result, but the actual results may vary across CPUs.
Types used in complex math
The Microsoft implementation of the complex.h header defines these types as equivalents for the C99 standard native complex types:
Standard type
Microsoft type
float complex or float _Complex
_Fcomplex
double complex or double _Complex
_Dcomplex
long double complex or long double _Complex
_Lcomplex
The math.h header defines a separate type, struct _complex, used for the _cabs function. The struct _complex type isn't used by the equivalent complex math functions cabs, cabsf, cabsl.
Complex constants and macros
I is defined as the complex type _Fcomplex initialized by { 0.0f, 1.0f }.
Because complex numbers aren't a native type in the Microsoft compiler, the standard arithmetic operators aren't defined on complex types. For convenience, these complex math library functions are provided to enable limited manipulation of complex numbers in user code: