LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

C99 complex numbers in CVI

Solved!
Go to solution

Hello all,

I'm trying to figure out the level of support of C99 complex numbers in CVI 2019. So far:

  • _Complex data type is present. complex is not.
  • _Complex_I or I constants are not present
  • complex.h is nowhere to be found
  • Only tgmath.h seems to make use of _Complex but it won't compile if I include it in a test program. Why ?
  • Basic arithmetic work: a+b, a*b
  • cimag() and creal() are missing, so how do I display a complex value since it's not a struct but a native type ?!?
  • std math functions such as exp() or sqrt() only compute on the real part of the complex argument
  • type generic macros as defined by tgmath don't compile as stated above
  • complex functions such as csqrt are missing
  • there is debugger support to display a complex, unlike what I'd read before. It displays it like a { real, imag } struct, but you can't use that trick in a printf, it won't compile.
0 Kudos
Message 1 of 3
(3,267 Views)
Solution
Accepted by topic author gdargaud

The solution that works on my computer;

  • First you should include the .h files attached herewith
  • Then, you can study the following example;

double complex R1;

double complex R2;

double complex R3;

double complex R4;

double complex C1;

double complex C2;

double complex C3;

double complex L1;

double complex L2;

R1=5.0 + 7.0*I;

R2= 34.0 – 34.0*I;

R3=45*I;

R4=34.0;

               

C1=1/(I*2*PI*nFrequency*1000000.0*nPANEL_C1/1000000.0);

C2=1/(I*2*PI*nFrequency*1000000.0*nPANEL_C2/1000000.0); C3=1/(I*2*PI*nFrequency*1000000.0*nPANEL_C3/1000000.0); L1=(I*2*PI*nFrequency*1000000.0*nPANEL_L1/1000000.0);sprintf(sPANEL_L1,"%f",nPANEL_L1); L2=(I*2*PI*nFrequency*1000000.0*nPANEL_L2/1000000.0);sprintf(sPANEL_L2,"%f",nPANEL_L2);          

double complex a=R2+C2;

double complex b=(a * nPANEL_MAINS)/(a + nPANEL_MAINS);

double complex c= b + L2;

double complex d=C1+R1;

double complex e= c*d/(c+d);

double complex f= e+L1;

double complex g= C3+((R3*R4)/(R3+R4));

double complex h= (f*g)/(f+g);

                                 

double Magnitute=pow((pow(creal(h),2)+pow(cimag(h),2)),0.5);

double Phase= atan(cimag(h)/creal(h))*180/PI;

Download All
Message 2 of 3
(1,848 Views)

Soydan,

Your example works and can even be debugged easily, but the c*() functions, such as ccos() are nowhere to be found. Is there a complex.lib that needs to be linked with the prog for that ?

0 Kudos
Message 3 of 3
(1,775 Views)