xref: /original-bsd/usr.bin/f77/libF77/pow_di.c (revision 5133e8a4)
1 /*-
2  * Copyright (c) 1980 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)pow_di.c	5.4 (Berkeley) 04/12/91";
10 #endif /* not lint */
11 
12 double
13 pow_di(ap, bp)
14 	double *ap;
15 	long *bp;
16 {
17 	register long n = *bp;
18 	double y, x = *ap;
19 
20 	if (!n)
21 		return((double)1);
22 	if (n < 0) {
23 		x = (double)1 / x;
24 		n = -n;
25 	}
26 	while (!(n&1)) {
27 		x *= x;
28 		n >>= 1;
29 	}
30 	for (y = x; --n > 0; y *= x)
31 		while (!(n&1)) {
32 			x *= x;
33 			n >>= 1;
34 		}
35 	return(y);
36 }
37