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

Yeah, it should read "repeat step three". Frequently, if you want to find x satisfying f(x) = x you can just let x be the limit of the sequence t, f(t), f(f(t)), f(f(f(t))) where t is some arbitrary number. In this case, we have:

  f(Y) = Y*(300-XYY)/200
If f(Y) = Y, then:

  Y = Y*(300-XYY)/200
  1 = (300-XYY)/200
  200 = 300 - XYY
  100 = XYY
So it looks like the algorithm calculates an inverse square root instead, and then multiplies it by the original number (step 5.)


Yeah, it should read "repeat step three".

Oops, quite right.

So it looks like the algorithm calculates an inverse square root instead, and then multiplies it by the original number (step 5.)

Exactly. The nice thing about this method is that it converges nicely even if you make errors (arithmetical or rounding) along the way -- so you can start by working with only a few digits and only use full precision right at the end.

You could compute square roots using a direct NR iteration (Y := (Y + X/Y) / 2), but that requires that you perform a division at each step -- most people find multiplications to be easier and faster.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

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

Search: