PDA

Click to See Complete Forum and Search --> : Square root???


NoteMe
Dec 14th, 2003, 05:47 PM
Do anyone know how you are calculation the scuare root of a number just using pen and paper....??? Or even Not sure what it is called but 3root?

NoteMe
Dec 14th, 2003, 05:49 PM
I guess I could use Newton Raphsons methid....but is there a formula?

Guv
Dec 26th, 2003, 10:05 PM
There is a process which looks a bit like long division that will do square root. It is more painful than the Newton succesive approximations method (assuming that you are good at guessing a first approximation). Given a hand calculator (without built in square root), nobody would consider using the long divison-like method rather than Newton.

In elementary school they taught the dumb method. My father taught me the Newton method, which I used. This resulted in an argument with my teacher who claimed that Newton was just guess work.

I ended up being forced to use the method taught in school. On each exam and homework paper involving square root, I wrote Dumb method!!

BTW: From a logical point of view, both long division and the similar square root method are actually equivalent to an iterative method resulting is successively better approximations.

abcdefg
Jan 17th, 2004, 01:58 PM
Here is code to find a square root from quake 3. It gets close to the inverse square root of a number using newtons method so the more iterations the more accurate it is.

This website explains what this code does and how to do it by hand.
http://www.magic-software.com/Docum...InverseSqrt.pdf



code:--------------------------------------------------------------------------------
float Q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5F;

x2 = number * 0.5F;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the ****?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed

return y;
}