Saturday, November 15, 2008

complier supporting c99 complex

Recently, I have been surveying the operations of complex. From the c99 and C++0x standard draft, I get the information about the operations for a complex library. Besides, I also refer to boost math library for how to implement the complex.

BTW, the boost 1.3.6 seems does not implement all the operations supported by the c++0x draft.

And, I try to use vc2005, icc10.1, gcc4.2, dmc8.5 to experience the complex operations.
But vc2005 and gcc4.3 do not support the c99 complex.
And some operations in icc&win32 will be broken( throw a access violation when using cacos).
It seems that the dmc can do more work to complex operation. At least it will work normally for cacos operation.

The following is the sample testing in the dmc:

#include "stdio.h"
#include "math.h"
#include "complex.h"

void outputComplex(_Complex double rst )
{
printf("rst=%g+%gi\n", rst);
}


int main()
{


//_Complex double a_ = 1.0+ 5.0i;//error

_Complex double a__ = 1.0+ 5.0 * _Complex_I;

_Complex double a = 1.0+ 5.0 * I;

outputComplex(a);

complex double b = cacos(a);

double complex b_ = cacos(a);

outputComplex(b);

return 0;

}

////////
The following is the sample for icc10.1&win32

#include "stdio.h"
#include "math.h"
#include "complex.h"

void outputComplex(_Complex double rst )
{
printf("rst=%g+%gi\n", rst);//print in the readable format
}

int main()
{
float f__=1.0f;
isnan(f__);

_Complex double a;
_Complex double b;

a=1.0+5.0i;
a+=2.0+2.0i;//a=3+7i

_Complex double a_ = 1.0+ 5.0 * _Complex_I;

_Complex double a__ = 1.0+ 5.0 * I;

printf("a=%g+%gi\n",a);//print in the readable format
//a = cproj(a);

a = 1.0 + 2.0i;
b = cacos(a);//--
outputComplex(b);

return 0;
}

No comments: