* configure.target (cpu_include_dir): Set to `config/cpu/m68k' for
[official-gcc.git] / libf2c / libF77 / c_div.c
blob4d153b4c4afc0df757822ff4ac747c312f600fc2
1 #include "f2c.h"
3 #ifdef KR_headers
4 extern VOID sig_die();
5 VOID c_div(c, a, b)
6 complex *a, *b, *c;
7 #else
8 extern void sig_die(char*,int);
9 void c_div(complex *c, complex *a, complex *b)
10 #endif
12 double ratio, den;
13 double abr, abi, cr;
15 if( (abr = b->r) < 0.)
16 abr = - abr;
17 if( (abi = b->i) < 0.)
18 abi = - abi;
19 if( abr <= abi )
21 if(abi == 0) {
22 #ifdef IEEE_COMPLEX_DIVIDE
23 float af, bf;
24 af = bf = abr;
25 if (a->i != 0 || a->r != 0)
26 af = 1.;
27 c->i = c->r = af / bf;
28 return;
29 #else
30 sig_die("complex division by zero", 1);
31 #endif
33 ratio = (double)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;
39 else
41 ratio = (double)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;
46 c->r = cr;