1998-02-01 02:37:08 +01:00
|
|
|
#include "f2c.h"
|
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
integer
|
|
|
|
pow_ii (integer * ap, integer * bp)
|
1998-02-01 02:37:08 +01:00
|
|
|
{
|
2002-06-01 14:38:32 +02:00
|
|
|
integer pow, x, n;
|
|
|
|
unsigned long u;
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02:00
|
|
|
x = *ap;
|
|
|
|
n = *bp;
|
1998-02-01 02:37:08 +01:00
|
|
|
|
2002-06-01 14:38:32 +02: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);
|
|
|
|
}
|