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