Skip to content

Instantly share code, notes, and snippets.

@Sinitca-Aleksandr
Created October 31, 2016 16:09
Show Gist options
  • Save Sinitca-Aleksandr/14d37326e8d51bd9703692ef09b78cf3 to your computer and use it in GitHub Desktop.
Save Sinitca-Aleksandr/14d37326e8d51bd9703692ef09b78cf3 to your computer and use it in GitHub Desktop.
static double sqrt(double target) {
double l_min = 0, l_max = 1000, cur = 100;
double err = 0.000000000000001;
while ((l_max - l_min) > err) {
if (cur * cur > target) {
l_max = cur;
cur = (cur + l_min) / 2;
} else {
l_min = cur;
cur = (l_max + cur) / 2;
}
}
return cur;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment