summaryrefslogtreecommitdiff
path: root/mysqrt.cpp
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-02-27 11:12:18 -0500
committerMichael Abed <michaelabed@gmail.com>2012-02-27 11:12:18 -0500
commit8932ac3c9881f800310e03fb147dce3261989eca (patch)
tree9336e291f283694c328933fb3ba00e6baa53acc9 /mysqrt.cpp
downloadec327-lab2-8932ac3c9881f800310e03fb147dce3261989eca.tar.gz
ec327-lab2-8932ac3c9881f800310e03fb147dce3261989eca.tar.bz2
ec327-lab2-8932ac3c9881f800310e03fb147dce3261989eca.zip
initial commit
Diffstat (limited to 'mysqrt.cpp')
-rw-r--r--mysqrt.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/mysqrt.cpp b/mysqrt.cpp
new file mode 100644
index 0000000..29fedf2
--- /dev/null
+++ b/mysqrt.cpp
@@ -0,0 +1,21 @@
+
+#include "mysqrt.h"
+
+using namespace std;
+double mysqrt(double x)
+{
+ bool goodenough = false;
+ double guess;
+ double last = x / 5.0;
+
+ if (x <= 0)
+ return x;
+
+ while (!goodenough) {
+ guess = (last + (x / last)) / 2.0;
+ last = guess;
+
+ goodenough = abs(guess - last) <= 0.000000001;
+ }
+ return guess;
+}