1998-02-01 09:37:08 +08:00
|
|
|
#include "f2c.h"
|
|
|
|
|
2002-06-01 20:38:32 +08:00
|
|
|
integer
|
|
|
|
pow_ii (integer * ap, integer * bp)
|
1998-02-01 09:37:08 +08:00
|
|
|
{
|
2002-06-01 20:38:32 +08:00
|
|
|
integer pow, x, n;
|
|
|
|
unsigned long u;
|
1998-02-01 09:37:08 +08:00
|
|
|
|
2002-06-01 20:38:32 +08:00
|
|
|
x = *ap;
|
|
|
|
n = *bp;
|
1998-02-01 09:37:08 +08:00
|
|
|
|
2002-06-01 20:38:32 +08:00
|
|
|
if (n <= 0)
|
|
|
|
{
|
|
|
|
if (n == 0 || x == 1)
|
|
|
|
return 1;
|
|
|
|
if (x != -1)
|
|
|
|
return x == 0 ? 1 / x : 0;
|
|
|
|
n = -n;
|
|
|
|
}
|
|
|
|
u = n;
|
|
|
|
for (pow = 1;;)
|
|
|
|
{
|
|
|
|
if (u & 01)
|
|
|
|
pow *= x;
|
|
|
|
if (u >>= 1)
|
|
|
|
x *= x;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (pow);
|
|
|
|
}
|