|
|
1.1 root 1: #include "complex"
2:
3: pow_zi(p, a, b) /* p = a**b */
4: dcomplex *p, *a;
5: long int *b;
6: {
7: long int n;
8: double t;
9: dcomplex x;
10: static dcomplex one = {1.0, 0.0};
11:
12: n = *b;
13: p->dreal = 1;
14: p->dimag = 0;
15:
16: if(n == 0)
17: return;
18: if(n < 0)
19: {
20: n = -n;
21: z_div(&x, &one, a);
22: }
23: else
24: {
25: x.dreal = a->dreal;
26: x.dimag = a->dimag;
27: }
28:
29: for( ; ; )
30: {
31: if(n & 01)
32: {
33: t = p->dreal * x.dreal - p->dimag * x.dimag;
34: p->dimag = p->dreal * x.dimag + p->dimag * x.dreal;
35: p->dreal = t;
36: }
37: if(n >>= 1)
38: {
39: t = x.dreal * x.dreal - x.dimag * x.dimag;
40: x.dimag = 2 * x.dreal * x.dimag;
41: x.dreal = t;
42: }
43: else
44: break;
45: }
46: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.