Commit | Line | Data |
---|---|---|
fdcfbf89 | 1 | /* |
3337a9c2 RE |
2 | * Copyright (c) 1980 Regents of the University of California. |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | * | |
a8b283ea | 6 | * @(#)z_div.c 5.3 %G% |
fdcfbf89 DW |
7 | */ |
8 | ||
9 | #include "complex" | |
50fd198f DL |
10 | #include <stdio.h> |
11 | #include <errno.h> | |
0ab3343e | 12 | #ifdef tahoe |
a8b283ea KB |
13 | #include <tahoe/math/FP.h> |
14 | #endif | |
fdcfbf89 DW |
15 | |
16 | z_div(c, a, b) | |
17 | dcomplex *a, *b, *c; | |
18 | { | |
19 | double ratio, den; | |
20 | double abr, abi; | |
21 | ||
0ab3343e | 22 | #ifndef tahoe |
fdcfbf89 DW |
23 | if( (abr = b->dreal) < 0.) |
24 | abr = - abr; | |
25 | if( (abi = b->dimag) < 0.) | |
26 | abi = - abi; | |
0ab3343e KM |
27 | #else tahoe |
28 | if( (abr = b->dreal) < 0.) | |
29 | *((long int *)&abr) ^= SIGN_BIT; | |
30 | if( (abi = b->dimag) < 0.) | |
31 | *((long int *)&abi) ^= SIGN_BIT; | |
32 | #endif tahoe | |
fdcfbf89 DW |
33 | if( abr <= abi ) |
34 | { | |
50fd198f DL |
35 | if(abi == 0) { |
36 | fprintf( stderr, "Double complex division by zero\n" ); | |
37 | f77_abort(EDOM); | |
38 | } | |
fdcfbf89 DW |
39 | ratio = b->dreal / b->dimag ; |
40 | den = b->dimag * (1 + ratio*ratio); | |
41 | c->dreal = (a->dreal*ratio + a->dimag) / den; | |
42 | c->dimag = (a->dimag*ratio - a->dreal) / den; | |
43 | } | |
44 | ||
45 | else | |
46 | { | |
47 | ratio = b->dimag / b->dreal ; | |
48 | den = b->dreal * (1 + ratio*ratio); | |
49 | c->dreal = (a->dreal + a->dimag*ratio) / den; | |
50 | c->dimag = (a->dimag - a->dreal*ratio) / den; | |
51 | } | |
52 | ||
53 | } |