Daid
Member
I need to do some integer based squareroots in the game I'm making. I currently use this code:
But my input is usualy around 0x100 to 0x10000 (never negative, no input checking needed), at that point this code might get a bit slow. There has to be some smart math way to do it alot faster, but I cannot find it. Any clues?
(Cannot use a lookup table, sometimes it goes all the way up to 0x10000000)
Code:
int INTsqrt(int a)
{
int square = 1;
int delta = 3;
while(square <= a)
{
square += delta;
delta += 2;
}
return (delta/2 - 1);
}
(Cannot use a lookup table, sometimes it goes all the way up to 0x10000000)