Skip to content

Instantly share code, notes, and snippets.

@BinRoot
Created November 24, 2012 03:40
Show Gist options
  • Select an option

  • Save BinRoot/4138256 to your computer and use it in GitHub Desktop.

Select an option

Save BinRoot/4138256 to your computer and use it in GitHub Desktop.
Sqrt.java
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