xref: /csrg-svn/usr.bin/f77/libF77/pow_ri.c (revision 47940)
1*47940Sbostic /*-
2*47940Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47940Sbostic  * All rights reserved.
422938Skre  *
5*47940Sbostic  * %sccs.include.proprietary.c%
610515Sdlw  */
710515Sdlw 
8*47940Sbostic #ifndef lint
9*47940Sbostic static char sccsid[] = "@(#)pow_ri.c	5.5 (Berkeley) 04/12/91";
10*47940Sbostic #endif /* not lint */
11*47940Sbostic 
1233391Sbostic #ifdef tahoe
1333391Sbostic #define	double	float
1433391Sbostic #endif /* tahoe */
1533391Sbostic 
1633391Sbostic float
pow_ri(ap,bp)1733391Sbostic pow_ri(ap, bp)
1833391Sbostic 	float *ap;
1933391Sbostic 	long *bp;
2010515Sdlw {
2133391Sbostic 	register long n = *bp;
2233391Sbostic #ifdef tahoe
2333391Sbostic 	register
2433391Sbostic #endif /* tahoe */
2533391Sbostic 	double y, x = *ap;
2610515Sdlw 
2733391Sbostic 	if (!n)
2833391Sbostic 		return((double)1);
2933391Sbostic 	if (n < 0) {
3033391Sbostic 		x = (double)1 / x;
3110515Sdlw 		n = -n;
3233391Sbostic 	}
3333391Sbostic 	while (!(n&1)) {
3433391Sbostic 		x *= x;
3533391Sbostic 		n >>= 1;
3633391Sbostic 	}
3733391Sbostic 	for (y = x; --n > 0; y *= x)
3833391Sbostic 		while (!(n&1)) {
3910515Sdlw 			x *= x;
4033391Sbostic 			n >>= 1;
4110515Sdlw 		}
4233391Sbostic 	return(y);
4310515Sdlw }
4433391Sbostic #ifdef tahoe
4533391Sbostic #undef double
4633391Sbostic #endif /* tahoe */
47