xref: /csrg-svn/usr.bin/f77/libF77/pow_ci.c (revision 29965)
110510Sdlw /*
222926Skre  * Copyright (c) 1980 Regents of the University of California.
322926Skre  * All rights reserved.  The Berkeley software License Agreement
422926Skre  * specifies the terms and conditions for redistribution.
522926Skre  *
6*29965Smckusick  *	@(#)pow_ci.c	5.2	11/03/86
710510Sdlw  */
810510Sdlw 
910510Sdlw #include "complex"
1010510Sdlw 
11*29965Smckusick #ifndef tahoe
1210510Sdlw pow_ci(p, a, b) 	/* p = a**b  */
1310510Sdlw complex *p, *a;
1410510Sdlw long int *b;
1510510Sdlw {
1610510Sdlw dcomplex p1, a1;
1710510Sdlw 
1810510Sdlw a1.dreal = a->real;
1910510Sdlw a1.dimag = a->imag;
2010510Sdlw 
2110510Sdlw pow_zi(&p1, &a1, b);
2210510Sdlw 
2310510Sdlw p->real = p1.dreal;
2410510Sdlw p->imag = p1.dimag;
2510510Sdlw }
26*29965Smckusick 
27*29965Smckusick #else tahoe
28*29965Smckusick 
29*29965Smckusick pow_ci(p, a, b) 	/* p = a**b  */
30*29965Smckusick complex *p, *a;
31*29965Smckusick long int *b;
32*29965Smckusick {
33*29965Smckusick register long int n;
34*29965Smckusick register float t;
35*29965Smckusick complex x;
36*29965Smckusick 
37*29965Smckusick n = *b;
38*29965Smckusick p->real = 1;
39*29965Smckusick p->imag = 0;
40*29965Smckusick 
41*29965Smckusick if(n == 0)
42*29965Smckusick 	return;
43*29965Smckusick if(n < 0)
44*29965Smckusick 	{
45*29965Smckusick 	n = -n;
46*29965Smckusick 	c_div(&x,p,a);
47*29965Smckusick 	}
48*29965Smckusick else
49*29965Smckusick 	{
50*29965Smckusick 	x.real = a->real;
51*29965Smckusick 	x.imag = a->imag;
52*29965Smckusick 	}
53*29965Smckusick 
54*29965Smckusick for( ; ; )
55*29965Smckusick 	{
56*29965Smckusick 	if(n & 01)
57*29965Smckusick 		{
58*29965Smckusick 		t = p->real * x.real - p->imag * x.imag;
59*29965Smckusick 		p->imag = p->real * x.imag + p->imag * x.real;
60*29965Smckusick 		p->real = t;
61*29965Smckusick 		}
62*29965Smckusick 	if(n >>= 1)
63*29965Smckusick 		{
64*29965Smckusick 		t = x.real * x.real - x.imag * x.imag;
65*29965Smckusick 		x.imag = 2 * x.real * x.imag;
66*29965Smckusick 		x.real = t;
67*29965Smckusick 		}
68*29965Smckusick 	else
69*29965Smckusick 		break;
70*29965Smckusick 	}
71*29965Smckusick }
72*29965Smckusick #endif tahoe
73