| 1 |
#include "f2c.h" |
| 2 |
#ifdef __cplusplus |
| 3 |
extern "C" { |
| 4 |
#endif |
| 5 |
|
| 6 |
#ifdef KR_headers |
| 7 |
extern VOID sig_die(); |
| 8 |
VOID z_div(c, a, b) doublecomplex *a, *b, *c; |
| 9 |
#else |
| 10 |
extern void sig_die(char*, int); |
| 11 |
void z_div(doublecomplex *c, doublecomplex *a, doublecomplex *b) |
| 12 |
#endif |
| 13 |
{ |
| 14 |
double ratio, den; |
| 15 |
double abr, abi, cr; |
| 16 |
|
| 17 |
if( (abr = b->r) < 0.) |
| 18 |
abr = - abr; |
| 19 |
if( (abi = b->i) < 0.) |
| 20 |
abi = - abi; |
| 21 |
if( abr <= abi ) |
| 22 |
{ |
| 23 |
if(abi == 0) { |
| 24 |
#ifdef IEEE_COMPLEX_DIVIDE |
| 25 |
if (a->i != 0 || a->r != 0) |
| 26 |
abi = 1.; |
| 27 |
c->i = c->r = abi / abr; |
| 28 |
return; |
| 29 |
#else |
| 30 |
sig_die("complex division by zero", 1); |
| 31 |
#endif |
| 32 |
} |
| 33 |
ratio = b->r / b->i ; |
| 34 |
den = b->i * (1 + ratio*ratio); |
| 35 |
cr = (a->r*ratio + a->i) / den; |
| 36 |
c->i = (a->i*ratio - a->r) / den; |
| 37 |
} |
| 38 |
|
| 39 |
else |
| 40 |
{ |
| 41 |
ratio = b->i / b->r ; |
| 42 |
den = b->r * (1 + ratio*ratio); |
| 43 |
cr = (a->r + a->i*ratio) / den; |
| 44 |
c->i = (a->i - a->r*ratio) / den; |
| 45 |
} |
| 46 |
c->r = cr; |
| 47 |
} |
| 48 |
#ifdef __cplusplus |
| 49 |
} |
| 50 |
#endif |