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
update for tahoe
[unix-history]
/
usr
/
src
/
usr.bin
/
f77
/
libF77
/
pow_hh.c
diff --git
a/usr/src/usr.bin/f77/libF77/pow_hh.c
b/usr/src/usr.bin/f77/libF77/pow_hh.c
index
c6915f2
..
68694c9
100644
(file)
--- a/
usr/src/usr.bin/f77/libF77/pow_hh.c
+++ b/
usr/src/usr.bin/f77/libF77/pow_hh.c
@@
-3,29
+3,58
@@
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
- * @(#)pow_hh.c 5.
1
%G%
+ * @(#)pow_hh.c 5.
2
%G%
*/
short pow_hh(ap, bp)
short *ap, *bp;
{
*/
short pow_hh(ap, bp)
short *ap, *bp;
{
-
shor
t pow, x, n;
+
short in
t pow, x, n;
-pow = 1;
-x = *ap;
-n = *bp;
+
pow = 1;
+
x = *ap;
+
n = *bp;
-if(n < 0)
- { }
-else if(n > 0)
- for( ; ; )
+ if (n == 0)
+ return ( 1L );
+
+ if (x == 0)
+ {
+ if( n > 0 )
+ return ( 0L );
+ else
+ return ( 1/x );
+ }
+
+ if (x == 1)
+ return ( 1L );
+
+ if (x == -1)
+ {
+ if (n < 0)
{
{
- if(n & 01)
- pow *= x;
- if(n >>= 1)
- x *= x;
+ if (n < -2)
+ n += 2;
+ n = -n;
+ }
+ if (n % 2 == 0)
+ return ( 1L );
else
else
- break;
+ return ( -1L );
+ }
+
+ if (n > 0)
+ for( ; ; )
+ {
+ if(n & 01)
+ pow *= x;
+ if(n >>= 1)
+ x *= x;
+ else
+ break;
}
}
-return(pow);
+ else
+ pow = 0;
+
+ return(pow);
}
}