X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/696f3a9ab60104c656510fd8d47195c98859943d..ca67e7b465996afb3821d6a075c4dc6a7f0f5d52:/usr/src/usr.lib/libF77/pow_di.c diff --git a/usr/src/usr.lib/libF77/pow_di.c b/usr/src/usr.lib/libF77/pow_di.c index c4a4628e9b..923bb7f0eb 100644 --- a/usr/src/usr.lib/libF77/pow_di.c +++ b/usr/src/usr.lib/libF77/pow_di.c @@ -1,34 +1,33 @@ -double pow_di(ap, bp) -double *ap; -long int *bp; -{ -double pow, x; -long int n; +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + * + * @(#)pow_di.c 5.3 1/19/88 + */ -pow = 1; -x = *ap; -n = *bp; +double +pow_di(ap, bp) + double *ap; + long *bp; +{ + register long n = *bp; + double y, x = *ap; -if(n != 0) - { - if(n < 0) - { - if(x == 0) - { - return(pow); - } + if (!n) + return((double)1); + if (n < 0) { + x = (double)1 / x; n = -n; - x = 1/x; - } - for( ; ; ) - { - if(n & 01) - pow *= x; - if(n >>= 1) + } + while (!(n&1)) { + x *= x; + n >>= 1; + } + for (y = x; --n > 0; y *= x) + while (!(n&1)) { x *= x; - else - break; + n >>= 1; } - } -return(pow); + return(y); }