debian/external_deps/fetk/punc/src/vf2c/pow_ii.c
raw| 1 | #include "f2c.h" |
| 2 | #ifdef __cplusplus |
| 3 | extern "C" { |
| 4 | #endif |
| 5 | |
| 6 | #ifdef KR_headers |
| 7 | integer pow_ii(ap, bp) integer *ap, *bp; |
| 8 | #else |
| 9 | integer pow_ii(integer *ap, integer *bp) |
| 10 | #endif |
| 11 | { |
| 12 | integer pow, x, n; |
| 13 | unsigned long u; |
| 14 | |
| 15 | x = *ap; |
| 16 | n = *bp; |
| 17 | |
| 18 | if (n <= 0) { |
| 19 | if (n == 0 || x == 1) |
| 20 | return 1; |
| 21 | if (x != -1) |
| 22 | return x == 0 ? 1/x : 0; |
| 23 | n = -n; |
| 24 | } |
| 25 | u = n; |
| 26 | for(pow = 1; ; ) |
| 27 | { |
| 28 | if(u & 01) |
| 29 | pow *= x; |
| 30 | if(u >>= 1) |
| 31 | x *= x; |
| 32 | else |
| 33 | break; |
| 34 | } |
| 35 | return(pow); |
| 36 | } |
| 37 | #ifdef __cplusplus |
| 38 | } |
| 39 | #endif |