不幸的是,早期的微軟並不急於提供C99庫支持,因爲它的用戶基數相對較小,並且很難將現代gcc代碼移植到MSVC。這是一個優先事項。
但是,對開發者的需求,他們已經實現了在Visual Studio 2013及以上的許多C99庫此處提到:
https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
因此,在C語言的代碼可以寫爲:
#include <stdio.h> /* Standard Library of Input and Output */
#include <complex.h> /* Standard Library of Complex Numbers */
int main() {
double complex z1 = 1.0 + 3.0 * I;
double complex z2 = 1.0 - 4.0 * I;
printf("Initial values: Z1 = %.2f + %.2fi \nZ2 = %.2f %+.2fi\n", creal(z1), cimag(z1), creal(z2), cimag(z2));
double complex sum = z1 + z2;
printf("Sum: Z1 + Z2 = %.2f %+.2fi\n", creal(sum), cimag(sum));
double complex diff = z1 - z2;
printf("Diff: Z1 - Z2 = %.2f %+.2fi\n", creal(difference), cimag(difference));
double complex product = z1 * z2;
printf("Product: Z1 x Z2 = %.2f %+.2fi\n", creal(product), cimag(product));
double complex quotient = z1/z2;
printf("Quotient: Z1/Z2 = %.2f %+.2fi\n", creal(quotient), cimag(quotient));
double complex conjugate = conj(z1);
printf("Conjugate of Z1 = %.2f %+.2fi\n", creal(conjugate), cimag(conjugate));
return 0;
}
功能,如COS(),實驗值()和SQRT()必須與它們複雜的形式,例如被替換ccos(),cexp(),csqrt(),他們工作得很好。
其他的解決方法可以是完全刮掉MS的編譯器和使用英特爾編譯器(這是更明智),其在Visual C.
更明智的做法是工作移動到英特爾CC或GCC,和使用Eclipse爲您的編程環境。不幸的是,跨Windows-Linux-Solaris-AIX等的代碼的可移植性通常很重要,MS工具根本不支持這些工具。
手卷你自己的複合類 –
'a'未初始化。請參閱此處瞭解更多詳情:http://en.cppreference.com/w/c/numeric/complex/Complex_I – vivekn