date and time created 83/01/21 11:16:51 by dlw
[unix-history] / usr / src / usr.bin / f77 / libF77 / pow_zi.c
CommitLineData
d6cc74ee
DW
1/*
2 * "@(#)pow_zi.c 1.1"
3 */
4
5#include "complex"
6
7pow_zi(p, a, b) /* p = a**b */
8dcomplex *p, *a;
9long int *b;
10{
11long int n;
12double t;
13dcomplex x;
14
15n = *b;
16p->dreal = 1;
17p->dimag = 0;
18
19if(n == 0)
20 return;
21if(n < 0)
22 {
23 n = -n;
24 z_div(&x, p, a);
25 }
26else
27 {
28 x.dreal = a->dreal;
29 x.dimag = a->dimag;
30 }
31
32for( ; ; )
33 {
34 if(n & 01)
35 {
36 t = p->dreal * x.dreal - p->dimag * x.dimag;
37 p->dimag = p->dreal * x.dimag + p->dimag * x.dreal;
38 p->dreal = t;
39 }
40 if(n >>= 1)
41 {
42 t = x.dreal * x.dreal - x.dimag * x.dimag;
43 x.dimag = 2 * x.dreal * x.dimag;
44 x.dreal = t;
45 }
46 else
47 break;
48 }
49}