xref: /csrg-svn/usr.bin/f77/libF77/pow_di.c (revision 22928)
110512Sdlw /*
2*22928Skre  * Copyright (c) 1980 Regents of the University of California.
3*22928Skre  * All rights reserved.  The Berkeley software License Agreement
4*22928Skre  * specifies the terms and conditions for redistribution.
5*22928Skre  *
6*22928Skre  *	@(#)pow_di.c	5.1	06/07/85
710512Sdlw  */
810512Sdlw 
910512Sdlw double pow_di(ap, bp)
1010512Sdlw double *ap;
1110512Sdlw long int *bp;
1210512Sdlw {
1310512Sdlw double pow, x;
1410512Sdlw long int n;
1510512Sdlw 
1610512Sdlw pow = 1;
1710512Sdlw x = *ap;
1810512Sdlw n = *bp;
1910512Sdlw 
2010512Sdlw if(n != 0)
2110512Sdlw 	{
2210512Sdlw 	if(n < 0)
2310512Sdlw 		{
2410512Sdlw 		if(x == 0)
2510512Sdlw 			{
2610512Sdlw 			return(pow);
2710512Sdlw 			}
2810512Sdlw 		n = -n;
2910512Sdlw 		x = 1/x;
3010512Sdlw 		}
3110512Sdlw 	for( ; ; )
3210512Sdlw 		{
3310512Sdlw 		if(n & 01)
3410512Sdlw 			pow *= x;
3510512Sdlw 		if(n >>= 1)
3610512Sdlw 			x *= x;
3710512Sdlw 		else
3810512Sdlw 			break;
3910512Sdlw 		}
4010512Sdlw 	}
4110512Sdlw return(pow);
4210512Sdlw }
43