1*47940Sbostic /*-
2*47940Sbostic * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic * All rights reserved.
422926Skre *
5*47940Sbostic * %sccs.include.proprietary.c%
610510Sdlw */
710510Sdlw
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)pow_ci.c 5.4 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic
1210510Sdlw #include "complex"
1310510Sdlw
1433391Sbostic #ifdef tahoe
1533391Sbostic
1633391Sbostic #define C_MULEQ(A,B) \
1733391Sbostic t = (A).real * (B).real - (A).imag * (B).imag,\
1833391Sbostic (A).imag = (A).real * (B).imag + (A).imag * (B).real,\
1933391Sbostic (A).real = t /* A *= B */
2033391Sbostic
2133391Sbostic void
pow_ci(p,a,b)2210510Sdlw pow_ci(p, a, b) /* p = a**b */
2333391Sbostic complex *p, *a;
2433391Sbostic long *b;
2510510Sdlw {
2633391Sbostic register long n = *b;
2733391Sbostic register float t;
2833391Sbostic complex x;
2910510Sdlw
3033391Sbostic x = *a;
3133391Sbostic p->real = (float)1, p->imag = (float)0;
3233391Sbostic if (!n)
3333391Sbostic return;
3433391Sbostic if (n < 0) {
3533391Sbostic c_div(&x, p, a);
3633391Sbostic n = -n;
3733391Sbostic }
3833391Sbostic while (!(n&1)) {
3933391Sbostic C_MULEQ(x, x);
4033391Sbostic n >>= 1;
4133391Sbostic }
4233391Sbostic for (*p = x; --n > 0; C_MULEQ(*p, x))
4333391Sbostic while (!(n&1)) {
4433391Sbostic C_MULEQ(x, x);
4533391Sbostic n >>= 1;
4633391Sbostic }
4733391Sbostic }
4810510Sdlw
4933391Sbostic #else /* !tahoe */
5010510Sdlw
5133391Sbostic extern void pow_zi();
5229965Smckusick
5333391Sbostic void
pow_ci(p,a,b)5429965Smckusick pow_ci(p, a, b) /* p = a**b */
5533391Sbostic complex *p, *a;
5633391Sbostic long *b;
5729965Smckusick {
5833391Sbostic dcomplex p1, a1;
5929965Smckusick
6033391Sbostic a1.dreal = a->real;
6133391Sbostic a1.dimag = a->imag;
6229965Smckusick
6333391Sbostic pow_zi(&p1, &a1, b);
6429965Smckusick
6533391Sbostic p->real = p1.dreal;
6633391Sbostic p->imag = p1.dimag;
6729965Smckusick }
6833391Sbostic
6933391Sbostic #endif /* tahoe */
70