Created
October 31, 2016 16:09
-
-
Save Sinitca-Aleksandr/14d37326e8d51bd9703692ef09b78cf3 to your computer and use it in GitHub Desktop.
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
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