i need a fast sqrt or Inverse sqrt for unsigned longs
usually you can get away with not using the square root for most game involved things. comparing distance squared is just as good as comparing distance, as long as you are just worried about relative distances. but otherwise just use the square root function. you can use a tailor series for the square root, but AFAIK that''s what the processor already uses. either that or a lookup table. either way, the processor will most likely be better at getting the square root faster than what you can come up with
-me
-me
well im currently using a lookup table but a faster sqrt that works for unsigned longs would be great.
Give this a go, I think it''s out of the Decent source code.
inline const long isqrt(register unsigned long x) { register unsigned long r, nr, m; r= 0; m= 0x40000000; do { nr= r + m; if (nr<=x) { x-= nr; r= nr + m; } r>>= 1; m>>= 2; } while (m!=0); if (x>r) r+= 1; return r;}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement