|
|
1.1 ! root 1: /* ! 2: * @(#)c_div.c 2.1 ! 3: */ ! 4: ! 5: #include "complex" ! 6: #include <stdio.h> ! 7: #include <errno.h> ! 8: ! 9: c_div(c, a, b) ! 10: register complex *a, *b, *c; ! 11: { ! 12: double ratio, den; ! 13: double abr, abi; ! 14: ! 15: if( (abr = b->real) < 0.) ! 16: abr = - abr; ! 17: if( (abi = b->imag) < 0.) ! 18: abi = - abi; ! 19: if( abr <= abi ) ! 20: { ! 21: if(abi == 0) { ! 22: fprintf(stderr,"complex division by zero\n"); ! 23: /* f77_abort(EDOM); */ ! 24: } ! 25: ratio = b->real / b->imag ; ! 26: den = b->imag * (1 + ratio*ratio); ! 27: c->real = (a->real*ratio + a->imag) / den; ! 28: c->imag = (a->imag*ratio - a->real) / den; ! 29: } ! 30: ! 31: else ! 32: { ! 33: ratio = b->imag / b->real ; ! 34: den = b->real * (1 + ratio*ratio); ! 35: c->real = (a->real + a->imag*ratio) / den; ! 36: c->imag = (a->imag - a->real*ratio) / den; ! 37: } ! 38: ! 39: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.