Created
November 24, 2012 03:40
-
-
Save BinRoot/4138256 to your computer and use it in GitHub Desktop.
Sqrt.java
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
| private static double sqrt(double n, double low, double high, double e) { | |
| double guess = (low+high)/2; | |
| if(Math.abs(guess*guess - n) < e) { | |
| return guess; | |
| } | |
| else if(guess*guess > n) { | |
| return sqrt(n, low, guess, e); | |
| } | |
| else { | |
| return sqrt(n, guess, high, e); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment