# Thread: Square Root of a number

1. whereas teh mothod I suggested does find 0 < x < 1 for all positive real numbers.

2. By the way, ((U - L)/2) is the same thing as (U + L) / 2.
Or, better yet, (U + L) >> 1.

EDIT:
didn't realize they were doubles

3. Are you sure bitshifting works with doubles, though?

4. Originally Posted by anon
Are you sure bitshifting works with doubles, though?
It doesnt. well, at least not as a fast divide by 2^N.

5. You're trying to calculate the square root by using the Newton-Raphson method by the looks of it. The problem is that you got the formula wrong. Go back and look it up again!

6. Originally Posted by iMalc
You're trying to calculate the square root by using the Newton-Raphson method by the looks of it. The problem is that you got the formula wrong. Go back and look it up again!
I think it's less Newton-Raphson and more binary search. (I guess "bisection" is the more proper term in this context.)

7. Heck I see; you're right. That's horrible!

8. If you want to get really fancy with square roots, here's a link describing how to calculate square roots by hand:

http://www.geocities.com/cnowlen/Cat...Squareroot.htm

I once implemented this in a class that does arithmetic on arbitrary length integers. Granted, it wasn't as efficient as the gmp implementation, but it's still cool to learn how to do.