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