Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

vaneger

i need a fast sqrt or Inverse sqrt for unsigned longs

This topic is 5230 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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

Share this post


Link to post
Share on other sites
well im currently using a lookup table but a faster sqrt that works for unsigned longs would be great.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!