Path: chuka.playstation.co.uk!news From: Alex Herbert Newsgroups: scee.yaroze.freetalk.english Subject: Square Root Date: Fri, 21 Aug 1998 16:24:59 +0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 26 Message-ID: <35DD914A.BBA25235@ndirect.co.uk> Reply-To: aherbert@ndirect.co.uk NNTP-Posting-Host: dialin2-38.ndirect.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) OK, I know that using square roots is best avoided, and in most cases they can be. But sometimes they just can't be avoided. I decided that using floating point was not the way to go, but I've never seen a square root algorithm before, so this is what I came up with. u_short sq_root(u_long n) { u_short a=0x8000; u_short b=0; u_short c; while(a) { c=a|b; if(c*c<=n) b=c; a=a>>1; } return(b); } It works fine, but does anyone know a better way to find the sqaure root of any u_long? Herbs