|
|
1.1 ! root 1: /* ! 2: * "@(#)z_div.c 1.1" ! 3: */ ! 4: ! 5: #include "complex" ! 6: ! 7: z_div(c, a, b) ! 8: dcomplex *a, *b, *c; ! 9: { ! 10: double ratio, den; ! 11: double abr, abi; ! 12: ! 13: if( (abr = b->dreal) < 0.) ! 14: abr = - abr; ! 15: if( (abi = b->dimag) < 0.) ! 16: abi = - abi; ! 17: if( abr <= abi ) ! 18: { ! 19: if(abi == 0) ! 20: abort(); /* fatal("complex division by zero"); */ ! 21: ratio = b->dreal / b->dimag ; ! 22: den = b->dimag * (1 + ratio*ratio); ! 23: c->dreal = (a->dreal*ratio + a->dimag) / den; ! 24: c->dimag = (a->dimag*ratio - a->dreal) / den; ! 25: } ! 26: ! 27: else ! 28: { ! 29: ratio = b->dimag / b->dreal ; ! 30: den = b->dreal * (1 + ratio*ratio); ! 31: c->dreal = (a->dreal + a->dimag*ratio) / den; ! 32: c->dimag = (a->dimag - a->dreal*ratio) / den; ! 33: } ! 34: ! 35: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.