Path: chuka.playstation.co.uk!news From: "Nick Slaven" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Square Root Date: Fri, 21 Aug 1998 18:23:02 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 42 Message-ID: <6rkb09$d2j11@chuka.playstation.co.uk> References: <35DD914A.BBA25235@ndirect.co.uk> <35DD9B1E.3FEAA1E5@scee.sony.co.uk> NNTP-Posting-Host: mfs2-dnbqy-166.gbr.compuserve.net X-Newsreader: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 James Russell wrote in message <35DD9B1E.3FEAA1E5@scee.sony.co.uk>... >> It works fine, but does anyone know a better way to find the square root >> of any u_long? Well heres one I rolled meself, I doubt if its better, haven't got time to check at the mo u_long ISqrt(u_long X) { int bitmax,Step=0; u_long V1,V2=0; // get 1st estimate for(bitmax=0,V1=X;V1!=0;bitmax++) V1>>=1; V1=X>>(bitmax>>1); // iterative approximation (takes about 4 steps, "Step" is for unequal values of V1&V2) while((V1!=V2)&&(Step++<10)) { V2=X/V1; V1=(V1+V2)>>1; } return V1; } The iteractive approximation is out of Schaums Basic Maths, the 1st estimate is something I thought up myself & was rather proud of until I discovered some very similar 1st aproximations at http://www.best.com/~mxmora/umpg/UMPG_II_Math&Algorithms.html cheers Nick (S)