Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Faster Aproximate Square Root?

Status
Not open for further replies.

Insider1984

Technical User
Feb 15, 2002
132
US
Is there a semi accurate method of calculating the approximate square root of a number?

We are using a distance formula on some shorts and would like to approximate the square root to save time.


Any ideas?

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
Am I missing the point? Why don't you use Math.Sqrt() to find the square root? It is late, so forgive me if I'm being daft.

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
Guru7777, the sqrt function provided is far to acurrate and too slow for our needs. If we can bit shift

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
As far as square root is a floating point number, there can't be any bit shifts.
So you either use the link earthandfire suggested, or use LookUp table as JohnYingling suggested. You probably won't get a faster method then using LookUp table, but it's memory consuming so you have to consider this too.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top