1994-10-26 19:17:41 +01:00
|
|
|
#include "f2c.h"
|
|
|
|
|
|
|
|
#ifdef KR_headers
|
|
|
|
extern VOID sig_die();
|
|
|
|
VOID c_div(c, a, b)
|
|
|
|
complex *a, *b, *c;
|
|
|
|
#else
|
|
|
|
extern void sig_die(char*,int);
|
|
|
|
void c_div(complex *c, complex *a, complex *b)
|
|
|
|
#endif
|
|
|
|
{
|
1997-04-13 03:16:58 +02:00
|
|
|
double ratio, den;
|
|
|
|
double abr, abi;
|
|
|
|
double ai = a->i, ar = a->r, bi = b->i, br = b->r;
|
1994-10-26 19:17:41 +01:00
|
|
|
|
1997-04-13 03:16:58 +02:00
|
|
|
if( (abr = br) < 0.)
|
|
|
|
abr = - abr;
|
|
|
|
if( (abi = bi) < 0.)
|
|
|
|
abi = - abi;
|
|
|
|
if( abr <= abi )
|
|
|
|
{
|
|
|
|
if(abi == 0)
|
|
|
|
sig_die("complex division by zero", 1);
|
|
|
|
ratio = (double)br / bi ;
|
|
|
|
den = bi * (1 + ratio*ratio);
|
|
|
|
c->r = (ar*ratio + ai) / den;
|
|
|
|
c->i = (ai*ratio - ar) / den;
|
|
|
|
}
|
1994-10-26 19:17:41 +01:00
|
|
|
|
1997-04-13 03:16:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ratio = (double)bi / br ;
|
|
|
|
den = br * (1 + ratio*ratio);
|
|
|
|
c->r = (ar + ai*ratio) / den;
|
|
|
|
c->i = (ai - ar*ratio) / den;
|
|
|
|
}
|
1994-10-26 19:17:41 +01:00
|
|
|
}
|