1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)pow_di.c 5.3 01/19/88 7 */ 8 9 double 10 pow_di(ap, bp) 11 double *ap; 12 long *bp; 13 { 14 register long n = *bp; 15 double y, x = *ap; 16 17 if (!n) 18 return((double)1); 19 if (n < 0) { 20 x = (double)1 / x; 21 n = -n; 22 } 23 while (!(n&1)) { 24 x *= x; 25 n >>= 1; 26 } 27 for (y = x; --n > 0; y *= x) 28 while (!(n&1)) { 29 x *= x; 30 n >>= 1; 31 } 32 return(y); 33 } 34