xref: /original-bsd/usr.bin/f77/libF77/c_div.c (revision 48d2e7c6)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)c_div.c	5.2 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 #include "complex"
13 #include <stdio.h>
14 #include <errno.h>
15 
16 c_div(c, a, b)
17 complex *a, *b, *c;
18 {
19 double ratio, den;
20 double abr, abi;
21 
22 if( (abr = b->real) < 0.)
23 	abr = - abr;
24 if( (abi = b->imag) < 0.)
25 	abi = - abi;
26 if( abr <= abi )
27 	{
28 	if(abi == 0) {
29 		fprintf(stderr,"complex division by zero\n");
30 		f77_abort(EDOM);
31 	}
32 	ratio = b->real / b->imag ;
33 	den = b->imag * (1 + ratio*ratio);
34 	c->real = (a->real*ratio + a->imag) / den;
35 	c->imag = (a->imag*ratio - a->real) / den;
36 	}
37 
38 else
39 	{
40 	ratio = b->imag / b->real ;
41 	den = b->real * (1 + ratio*ratio);
42 	c->real = (a->real + a->imag*ratio) / den;
43 	c->imag = (a->imag - a->real*ratio) / den;
44 	}
45 
46 }
47