Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Some challenging C code
Message
De
20/12/2006 11:26:38
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
 
 
À
20/12/2006 09:43:17
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01179188
Message ID:
01179233
Vues:
9
>I've been porting an old application into FoxPro this week and thought I'd have it finished up pretty quickly...until I hit this particular function. It's some C code that's heavy on complex number arithmetic. I went at it from a couple different angles (handling complex numbers as arrays, handling them as objects) in Fox, but in the end, I never got anything very promising. Anyone have any smart ideas on converting this function into FoxPro? Thanks!
>
>
>void laguer(Complex a[], int m, Complex *x, int *its)
>{
>  int iter, j;
>  double abx, abp, abm, err;
>  Complex dx,x1, b, d, f, g, h, sq, gp, gm, g2;
>  static double frac[MR+1] = {0.0, 0.5, 0.25, 0.75, 0.13,
>				0.38, 0.62, 0.88, 1.0};
>  Complex xx, yy;
>
>  for (iter = 1; iter <= MAXIT; iter++) {
>    *its = iter;
>    b = a[m];
>    err = abs(b);
>    d = f = Complex(0.0, 0.0);
>    abx = abs(*x);
>    for (j=m-1;j>=0;j--) {
>      f = f = (*x) * f + d;
>      d = (*x) * d + b;
>      b = (*x) * b + a[j];
>      err = abs(b) + abx * err;
>    }
>    err *= EPSS;
>
>    if ( abs(b) <= err ) return;
>    g = d/b;
>    g2 = g*g;
>    h = g2 - f/b * 2.0;
>    sq = sqrt( (h*(m*1.0) - g2) * ((m-1)*1.0) );
>    gp = g + sq;
>    gm = g - sq;
>    abp = abs(gp);
>    abm = abs(gm);
>    if (abp < abm) gp=gm;
>
>    dx = (((abp > 0.0) || (abm>0))
>	  ? Complex(m,0)/gp
>	  : Complex( cos(iter), sin(iter)) * exp( log(1+abx) ) );
>
>	//   : Complex( cos(iter), sin(iter) ) * exp( log(1+abx) ) );
>
>    x1 = *x - dx;
>    if (real(*x) == real(x1) && imag(*x) == imag(x1)) return;
>    if (iter % MT) *x = x1;
>    else *x = *x - frac[iter/MT] * dx;
>  }
>  assert( 0 );
>  // exit(1);
>}
>
Um... you'd have to reinvent complex arithmetics, best as a custom class and/or a set of functions or methods to this class. You'd need a method to add, multiply, divide, take module, take real part, take imaginary part of such numbers... and then eventually figure what's this code actually doing.
The part which doesn't make sense to me is that it takes sin() and cos() of an integer. Does c++ work in degrees?

Which complex function is this supposed to calculate? The name LaGuer doesn't sound familiar.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform