Hacker News new | ask | show | jobs
by Corun 1226 days ago
Knowing powers of two in your head (as I guess many of us do) can helps with root estimates and this algorithm.

Take an example sqrt(5819): That's between two powers of two 2^12 = 4096 and 2^13 = 8192. The square roots of those numbers are easy, since you just half the exponent sqrt(4096) = 2^6 = 64

That gives us our initial estimate g for the algorithm from the article. Now we do: b = n / g = 5819 / 64 To do this division in our head we remember that we already know 4096 is 64 x 64. So we just need the remainder (5819 - 4096) / 64 ~= 1700 / 64. Now that's low enough that I can approximate it in my head 64 * 30 is too high by about 3 * 64 so the answer should be around 27 (actual answer 26.5). So b = 64 + 27 = 91

So now we finish the algorithm, sqrt(5819) ~= g + b / 2 = (64 + 91 / 2) = 77.5.

So, how did we do?

The actual sqrt is 76.28, so seems pretty good!