Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just out of curiosity, what's the advantage of `(2/x + x)/2` over `x/2 + 1/x` (which, to me, is more readable)?


It is more readable. But I wanted to stick close to the general formula [1], so that you see what's going on. It would probably have been better to write it as:

  y = 2
  average x1 x2 = (x1 + x2) / 2
  next x = average (y/x + x)
It's just a co-incidence that I chose y as 2.

[1] Heron's Method (http://en.wikipedia.org/wiki/Herons_method#Babylonian_method)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: