Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
pow_ii.c
Go to the documentation of this file.00001 #include "f2c.h"
00002
00003 #ifdef KR_headers
00004 integer pow_ii(ap, bp) integer *ap, *bp;
00005 #else
00006 integer pow_ii(integer *ap, integer *bp)
00007 #endif
00008 {
00009 integer pow, x, n;
00010 unsigned long u;
00011
00012 x = *ap;
00013 n = *bp;
00014
00015 if (n <= 0) {
00016 if (n == 0 || x == 1)
00017 return 1;
00018 if (x != -1)
00019 return x == 0 ? 1/x : 0;
00020 n = -n;
00021 }
00022 u = n;
00023 for(pow = 1; ; )
00024 {
00025 if(u & 01)
00026 pow *= x;
00027 if(u >>= 1)
00028 x *= x;
00029 else
00030 break;
00031 }
00032 return(pow);
00033 }