1 /*-
2 * Copyright (c) 1980 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * %sccs.include.proprietary.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)pow_ci.c 5.4 (Berkeley) 04/12/91";
10 #endif /* not lint */
11
12 #include "complex"
13
14 #ifdef tahoe
15
16 #define C_MULEQ(A,B) \
17 t = (A).real * (B).real - (A).imag * (B).imag,\
18 (A).imag = (A).real * (B).imag + (A).imag * (B).real,\
19 (A).real = t /* A *= B */
20
21 void
pow_ci(p,a,b)22 pow_ci(p, a, b) /* p = a**b */
23 complex *p, *a;
24 long *b;
25 {
26 register long n = *b;
27 register float t;
28 complex x;
29
30 x = *a;
31 p->real = (float)1, p->imag = (float)0;
32 if (!n)
33 return;
34 if (n < 0) {
35 c_div(&x, p, a);
36 n = -n;
37 }
38 while (!(n&1)) {
39 C_MULEQ(x, x);
40 n >>= 1;
41 }
42 for (*p = x; --n > 0; C_MULEQ(*p, x))
43 while (!(n&1)) {
44 C_MULEQ(x, x);
45 n >>= 1;
46 }
47 }
48
49 #else /* !tahoe */
50
51 extern void pow_zi();
52
53 void
pow_ci(p,a,b)54 pow_ci(p, a, b) /* p = a**b */
55 complex *p, *a;
56 long *b;
57 {
58 dcomplex p1, a1;
59
60 a1.dreal = a->real;
61 a1.dimag = a->imag;
62
63 pow_zi(&p1, &a1, b);
64
65 p->real = p1.dreal;
66 p->imag = p1.dimag;
67 }
68
69 #endif /* tahoe */
70