Calculations may not converge in a finite number of steps:
Providing a maximum number of iterations will guarantee termination:
Using a numerical test for convergence works in this case as well:
Sometimes convergence may fail on certain platforms due to insufficient accuracy of a machine arithmetic library function. This can be addressed by using a comparison function with a larger tolerance: