xref: /csrg-svn/usr.bin/f77/libF77/pow_di.c (revision 33364)
110512Sdlw /*
222928Skre  * Copyright (c) 1980 Regents of the University of California.
322928Skre  * All rights reserved.  The Berkeley software License Agreement
422928Skre  * specifies the terms and conditions for redistribution.
522928Skre  *
6*33364Sbostic  *	@(#)pow_di.c	5.3	01/19/88
710512Sdlw  */
810512Sdlw 
9*33364Sbostic double
10*33364Sbostic pow_di(ap, bp)
11*33364Sbostic 	double *ap;
12*33364Sbostic 	long *bp;
1310512Sdlw {
14*33364Sbostic 	register long n = *bp;
15*33364Sbostic 	double y, x = *ap;
1610512Sdlw 
17*33364Sbostic 	if (!n)
18*33364Sbostic 		return((double)1);
19*33364Sbostic 	if (n < 0) {
20*33364Sbostic 		x = (double)1 / x;
2110512Sdlw 		n = -n;
22*33364Sbostic 	}
23*33364Sbostic 	while (!(n&1)) {
24*33364Sbostic 		x *= x;
25*33364Sbostic 		n >>= 1;
26*33364Sbostic 	}
27*33364Sbostic 	for (y = x; --n > 0; y *= x)
28*33364Sbostic 		while (!(n&1)) {
2910512Sdlw 			x *= x;
30*33364Sbostic 			n >>= 1;
3110512Sdlw 		}
32*33364Sbostic 	return(y);
3310512Sdlw }
34