corrections by Bob Corbett. DLW
authorDavid Wasley <dlw@ucbvax.Berkeley.EDU>
Sat, 16 Apr 1983 00:23:15 +0000 (16:23 -0800)
committerDavid Wasley <dlw@ucbvax.Berkeley.EDU>
Sat, 16 Apr 1983 00:23:15 +0000 (16:23 -0800)
SCCS-vsn: usr.bin/f77/libF77/pow_ii.c 1.2

usr/src/usr.bin/f77/libF77/pow_ii.c

index a4806f2..2440cfa 100644 (file)
@@ -1,27 +1,56 @@
 /*
 /*
- *     "@(#)pow_ii.c   1.1"
+ *     "@(#)pow_ii.c   1.2"
+ *
+ *  Corrections by Robert P. Corbett, 1983 March 2
+ *  Revised to restore portability, 1983 March 4
  */
 
  */
 
+
 long int pow_ii(ap, bp)
 long int *ap, *bp;
 {
 long int pow_ii(ap, bp)
 long int *ap, *bp;
 {
-long int pow, x, n;
+       long int pow, x, n;
+       int zero = 0;
+
+       pow = 1;
+       x = *ap;
+       n = *bp;
+
+       if (n == 0)
+               return ( 1L );
+
+       if (x == 0)
+               return ( 0L );
 
 
-pow = 1;
-x = *ap;
-n = *bp;
+       if (x == 1)
+               return ( 1L );
 
 
-if(n < 0)
-       { }
-else if(n > 0)
-       for( ; ; )
+       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);
 }
 }