Created
May 22, 2012 19:53
-
-
Save git2samus/2771253 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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