xref: /original-bsd/usr.bin/f77/libF77/c_div.c (revision 92d3de31)
1 /*
2  *	"@(#)c_div.c	1.1"
3  */
4 
5 #include "complex"
6 
7 c_div(c, a, b)
8 complex *a, *b, *c;
9 {
10 double ratio, den;
11 double abr, abi;
12 
13 if( (abr = b->real) < 0.)
14 	abr = - abr;
15 if( (abi = b->imag) < 0.)
16 	abi = - abi;
17 if( abr <= abi )
18 	{
19 	if(abi == 0)
20 		abort(); /* fatal("complex division by zero"); */
21 	ratio = b->real / b->imag ;
22 	den = b->imag * (1 + ratio*ratio);
23 	c->real = (a->real*ratio + a->imag) / den;
24 	c->imag = (a->imag*ratio - a->real) / den;
25 	}
26 
27 else
28 	{
29 	ratio = b->imag / b->real ;
30 	den = b->real * (1 + ratio*ratio);
31 	c->real = (a->real + a->imag*ratio) / den;
32 	c->imag = (a->imag - a->real*ratio) / den;
33 	}
34 
35 }
36