2003-05-15 Eric Christopher <echristo@redhat.com>
[official-gcc.git] / libf2c / libF77 / pow_zi.c
blob214db3d7a0fb3a4c7c29383eda391adad3376beb
1 #include "f2c.h"
3 extern void z_div (doublecomplex *, doublecomplex *, doublecomplex *);
4 void
5 pow_zi (doublecomplex * p, doublecomplex * a, integer * b) /* p = a**b */
7 integer n;
8 unsigned long u;
9 double t;
10 doublecomplex q, x;
11 static doublecomplex one = { 1.0, 0.0 };
13 n = *b;
14 q.r = 1;
15 q.i = 0;
17 if (n == 0)
18 goto done;
19 if (n < 0)
21 n = -n;
22 z_div (&x, &one, a);
24 else
26 x.r = a->r;
27 x.i = a->i;
30 for (u = n;;)
32 if (u & 01)
34 t = q.r * x.r - q.i * x.i;
35 q.i = q.r * x.i + q.i * x.r;
36 q.r = t;
38 if (u >>= 1)
40 t = x.r * x.r - x.i * x.i;
41 x.i = 2 * x.r * x.i;
42 x.r = t;
44 else
45 break;
47 done:
48 p->i = q.i;
49 p->r = q.r;