Reputation: 1
I've written an application using Xcode (in C), which relies heavily on the use of complex numbers. i.e. :
#include <complex.h>
...
float a, b;
complex float z;
z = a + I * b;
... etc
Now, this notation for complex numbers works great in Xcode, and was the perfect solution when building OS X compatible versions of the application. However, now I have a need to build a Windows version, so I have imported the same code into Visual Studio 2015. But unfortunately, this notation does not work, as VS's implementation of complex numbers is very different. And after researching my issue, I have failed to find any helpful information regarding how to handle complex numbers in such a manner, as to compile successfully on both IDEs.
This is perhaps due to my poor understanding of this C99 standard or maybe it is simply not possible. But, while I feel I could rewrite the C code using VS's own way of handling complex numbers, this would not be ideal, as I now plan to develop the application further for both OSs. And it would take too much time to write two versions of the same code in parallel.
Upvotes: 0
Views: 950
Reputation: 16540
as shown in: 'Compiling C code in Visual Studio 2013 with complex.h library'
_Dcomplex dc1 = {3.0, 2.0};
for the variable declaration.
From looking inside VS2013's "complex.h" header, it seems that Microsoft decided on their own implementation for C complex numbers. You'll have to implement your own arithmetical operators using the real() and imag() functions, i.e.:
double real_part = real(dc1) + real(dc2);
double imag_part = imag(dc1) + imag(dc2);
_Dcomplex result = {real_part, imag_part};
I doubt that microsoft has corrected the complex.h
header, so you should examine the complex.h
header file for the details for the float
types
Upvotes: 1