summaryrefslogtreecommitdiff
path: root/mysqrt.cpp
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-03-03 23:32:27 -0500
committerMichael Abed <michaelabed@gmail.com>2012-03-03 23:32:27 -0500
commitf2566da91396bc07356601794fd5db858a78f1f3 (patch)
tree6d18e7e9a517163dee5929eef6617cce12cfb415 /mysqrt.cpp
parent12993b517ff2f8ec6608c2deaf3e988c64f7f164 (diff)
downloadec327-lab2-f2566da91396bc07356601794fd5db858a78f1f3.tar.gz
ec327-lab2-f2566da91396bc07356601794fd5db858a78f1f3.tar.bz2
ec327-lab2-f2566da91396bc07356601794fd5db858a78f1f3.zip
make basically everything work
Diffstat (limited to 'mysqrt.cpp')
-rw-r--r--mysqrt.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/mysqrt.cpp b/mysqrt.cpp
index 18bb632..ddcda6f 100644
--- a/mysqrt.cpp
+++ b/mysqrt.cpp
@@ -7,7 +7,7 @@ double mysqrt(double x)
bool goodenough = false;
double lastGuess, nextGuess;
- lastGuess = x / 10.0;
+ lastGuess = x / 2;
if (x <= 0)
return x;
@@ -15,9 +15,9 @@ double mysqrt(double x)
while (!goodenough) {
nextGuess = (lastGuess + (x / lastGuess)) / 2.0;
+ goodenough = abs(nextGuess - lastGuess) <= 0.00001;
lastGuess = nextGuess;
- goodenough = abs(nextGuess - lastGuess) <= 0.000000000001;
}
return nextGuess;
}