#### Archived

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

# i need a fast sqrt or Inverse sqrt for unsigned longs

## Recommended Posts

vaneger    100
any one have somethign that will work with those?

##### Share on other sites
Palidine    1315
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 on other sites
31337    100
Too true, when it comes to square roots let the sqrt command worry about it

##### Share on other sites
vaneger    100
well im currently using a lookup table but a faster sqrt that works for unsigned longs would be great.

##### Share on other sites
iMalc    2466
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;}