| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "f2c.h" |
| 26 |
|
| 27 |
#ifdef KR_headers |
| 28 |
integer pow_ii(ap, bp) integer *ap, *bp; |
| 29 |
#else |
| 30 |
integer pow_ii(integer *ap, integer *bp) |
| 31 |
#endif |
| 32 |
{ |
| 33 |
integer pow, x, n; |
| 34 |
unsigned long u; |
| 35 |
|
| 36 |
x = *ap; |
| 37 |
n = *bp; |
| 38 |
|
| 39 |
if (n <= 0) { |
| 40 |
if (n == 0 || x == 1) |
| 41 |
return 1; |
| 42 |
if (x != -1) |
| 43 |
return x == 0 ? 0 : 1/x; |
| 44 |
n = -n; |
| 45 |
} |
| 46 |
u = n; |
| 47 |
for(pow = 1; ; ) |
| 48 |
{ |
| 49 |
if(u & 01) |
| 50 |
pow *= x; |
| 51 |
if(u >>= 1) |
| 52 |
x *= x; |
| 53 |
else |
| 54 |
break; |
| 55 |
} |
| 56 |
return(pow); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#ifdef KR_headers |
| 62 |
double r_sign(a,b) real *a, *b; |
| 63 |
#else |
| 64 |
double r_sign(real *a, real *b) |
| 65 |
#endif |
| 66 |
{ |
| 67 |
double x; |
| 68 |
x = (*a >= 0 ? *a : - *a); |
| 69 |
return( *b >= 0 ? x : -x); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
#ifdef KR_headers |
| 75 |
double floor(); |
| 76 |
integer i_nint(x) real *x; |
| 77 |
#else |
| 78 |
#undef abs |
| 79 |
#include "math.h" |
| 80 |
integer i_nint(real *x) |
| 81 |
#endif |
| 82 |
{ |
| 83 |
return( (integer)((*x)>=0 ? |
| 84 |
floor(*x + .5) : -floor(.5 - *x)) ); |
| 85 |
} |