The ISO/iec9899: 1999 standard (commonly known as c99) introduces a complex database that is very useful for the signal processing field and is also very convenient to use. Enable c99, gnu99, C11, or gnu11 for your c language compiler and include <complex. h> in the source file.
The c99 standard introduces two keywords used to describe the plural: _ complex and _ imaginary. _ Complex is used in combination with float and double to represent a plural number. Since the gcc4.6 version I used does not yet support the _ imaginary keyword (I don't think it will be supported in my life), I will not introduce it here. _ Imaginary indicates the imaginary part of a plural number. I estimate the number defined by _ imaginary as a pure virtual number.
If _ complex is used in combination with a float, both the number part and the virtual part are in the float type. If you want to use a constant to represent the pure virtual number of a single precision floating point, you can actually write it like this: 1.0if, here I and F can be either the size or lower case, therefore, writing to 1.0if is no problem, and the compiler will not be stupid enough to use this if as a condition to judge the keyword.
If _ complex is used in combination with a double type, both the number part and the virtual number part are of the double type. If you want to use a constant to represent the pure virtual number of a double-precision floating point, you can write it as follows: 1.0i.
BelowCodeFragment. You can run it:
# Include <math. h> # include <stdio. h> # include <complex. h> int main (void) {float _ complex F =-1.0f; F = csqrtf (f) + 1.0if; printf ("the complex number is: % G + I % G \ n ", crealf (F), cimagf (f); double _ complex d = cexp (2.0i * m_pi ); printf ("e ^ (i2pi) = % F + I % F \ n", Creal (D), cimag (d ));}
The Creal (double _ complex) in the library function is to take the real part of a complex number; cimag (double _ complex) is to take the virtual part of a complex number.