projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
BSD 4_3_Tahoe release
[unix-history]
/
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
c4a4628
..
923bb7f
100644
(file)
--- 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;
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;
x *= x;
- else
- break;
+ n >>= 1;
}
}
- }
-return(pow);
+ return(y);
}
}