Commit | Line | Data |
---|---|---|
0ee0e326 BJ |
1 | struct dcomplex { double dreal, dimag; }; |
2 | ||
3 | z_div(c, a, b) | |
4 | struct dcomplex *a, *b, *c; | |
5 | { | |
6 | double ratio, den; | |
7 | double abr, abi; | |
8 | ||
9 | if( (abr = b->dreal) < 0.) | |
10 | abr = - abr; | |
11 | if( (abi = b->dimag) < 0.) | |
12 | abi = - abi; | |
13 | if( abr <= abi ) | |
14 | { | |
15 | if(abi == 0) | |
16 | abort(); /* fatal("complex division by zero"); */ | |
17 | ratio = b->dreal / b->dimag ; | |
18 | den = b->dimag * (1 + ratio*ratio); | |
19 | c->dreal = (a->dreal*ratio + a->dimag) / den; | |
20 | c->dimag = (a->dimag*ratio - a->dreal) / den; | |
21 | } | |
22 | ||
23 | else | |
24 | { | |
25 | ratio = b->dimag / b->dreal ; | |
26 | den = b->dreal * (1 + ratio*ratio); | |
27 | c->dreal = (a->dreal + a->dimag*ratio) / den; | |
28 | c->dimag = (a->dimag - a->dreal*ratio) / den; | |
29 | } | |
30 | ||
31 | } |