Last active
December 26, 2015 05:28
-
-
Save gitawego/7100484 to your computer and use it in GitHub Desktop.
Newton's Method to get square root
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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