Debian Codegraph @

debian/external_deps/fetk/punc/src/vf2c/pow_zi.c

raw
1 #include "f2c.h"
2 #ifdef __cplusplus
3 extern "C" {
4 #endif
5
6 #ifdef KR_headers
7 VOID pow_zi(p, a, b) /* p = a**b */
8 doublecomplex *p, *a; integer *b;
9 #else
10 extern void z_div(doublecomplex*, doublecomplex*, doublecomplex*);
11 void pow_zi(doublecomplex *p, doublecomplex *a, integer *b) /* p = a**b */
12 #endif
13 {
14 integer n;
15 unsigned long u;
16 double t;
17 doublecomplex q, x;
18 static doublecomplex one = {1.0, 0.0};
19
20 n = *b;
21 q.r = 1;
22 q.i = 0;
23
24 if(n == 0)
25 goto done;
26 if(n < 0)
27 {
28 n = -n;
29 z_div(&x, &one, a);
30 }
31 else
32 {
33 x.r = a->r;
34 x.i = a->i;
35 }
36
37 for(u = n; ; )
38 {
39 if(u & 01)
40 {
41 t = q.r * x.r - q.i * x.i;
42 q.i = q.r * x.i + q.i * x.r;
43 q.r = t;
44 }
45 if(u >>= 1)
46 {
47 t = x.r * x.r - x.i * x.i;
48 x.i = 2 * x.r * x.i;
49 x.r = t;
50 }
51 else
52 break;
53 }
54 done:
55 p->i = q.i;
56 p->r = q.r;
57 }
58 #ifdef __cplusplus
59 }
60 #endif