whereas teh mothod I suggested does find 0 < x < 1 for all positive real numbers.
Printable View
whereas teh mothod I suggested does find 0 < x < 1 for all positive real numbers.
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
Are you sure bitshifting works with doubles, though?
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!
Heck I see; you're right. That's horrible!
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.