Skip to content

Instantly share code, notes, and snippets.

@git2samus
Created May 22, 2012 19:53
Show Gist options
  • Select an option

  • Save git2samus/2771253 to your computer and use it in GitHub Desktop.

Select an option

Save git2samus/2771253 to your computer and use it in GitHub Desktop.
function squareGuessFactory(x) {
var guess=1;
return function() {
guess -= (guess*guess-x) / (2*guess);
return guess;
};
};
function newton_square_root(x, e) {
var square_guess = squareGuessFactory(x);
while (true) {
var guess = square_guess();
if (Math.abs(x - guess*guess) <= e)
return guess;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment