Skip to content

Instantly share code, notes, and snippets.

@gitawego
Last active December 26, 2015 05:28
Show Gist options
  • Save gitawego/7100484 to your computer and use it in GitHub Desktop.
Save gitawego/7100484 to your computer and use it in GitHub Desktop.
Newton's Method to get square root
function sqrt_iter(g, y) {
if (Math.abs(g*g - y) < 0.000000000000001) {
return g;
} else {
return sqrt_iter( (g + y / g)/2, y );
}
}
function sqrt(y) {
return sqrt_iter(1.0, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment