Original Post
can anyone point me in the right direction for a power of function that uses ints not floats/doubles?
eg
2 ^ 3
not
2.0 ^ 3.0
Thanks
eg
2 ^ 3
not
2.0 ^ 3.0
Thanks
int ipow(int base, unsigned int exp) { int result = 1; do { if(exp & 1) result *= base; base *= base; } while(exp >>= 1); return result;}
int power(int base, unsigned int exponent) { int result = 1; while (exponent--) result *= base; return result;}for(int x=div; x > 0; x--) array_max *= 2;Quote:
Original post by frogtag
Cheers. Although the while loop was destructive to the div value, with a little alteration I removed the function and achieved the same result keeping div intact.
*** Source Snippet Removed ***
Quote:You've hard-coded that to powers of two. I.e simply calculates array_max = array_max * 2^div (where ^ denotes to-the-power-of)
Original post by frogtag
Cheers. Although the while loop was destructive to the div value, with a little alteration I removed the function and achieved the same result keeping div intact.
*** Source Snippet Removed ***
array_max = array_max << div;
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more