|
Last change
on this file since 603 was 2, checked in by bird, 23 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
863 bytes
|
| Line | |
|---|
| 1 | #include "f2c.h"
|
|---|
| 2 |
|
|---|
| 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
|
|---|
| 11 | {
|
|---|
| 12 | double ratio, den;
|
|---|
| 13 | double abr, abi, cr;
|
|---|
| 14 |
|
|---|
| 15 | if( (abr = b->r) < 0.)
|
|---|
| 16 | abr = - abr;
|
|---|
| 17 | if( (abi = b->i) < 0.)
|
|---|
| 18 | abi = - abi;
|
|---|
| 19 | if( abr <= abi )
|
|---|
| 20 | {
|
|---|
| 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
|
|---|
| 32 | }
|
|---|
| 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;
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | else
|
|---|
| 40 | {
|
|---|
| 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;
|
|---|
| 45 | }
|
|---|
| 46 | c->r = cr;
|
|---|
| 47 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.