summaryrefslogtreecommitdiffstats
path: root/Scala/sqrt/sqrt.scala
diff options
context:
space:
mode:
Diffstat (limited to 'Scala/sqrt/sqrt.scala')
-rw-r--r--Scala/sqrt/sqrt.scala27
1 files changed, 0 insertions, 27 deletions
diff --git a/Scala/sqrt/sqrt.scala b/Scala/sqrt/sqrt.scala
deleted file mode 100644
index b99d61e..0000000
--- a/Scala/sqrt/sqrt.scala
+++ /dev/null
@@ -1,27 +0,0 @@
-
-object Main extends App {
-
- def abs(x:Double) = if (x < 0) -x else x
-
- def sqrt(x: Double) = {
-
- def sqrtIter(guess: Double): Double =
- if (isGoodEnough(guess)) guess
- else sqrtIter(improve(guess))
-
- def isGoodEnough(guess: Double) =
- abs(guess * guess - x ) /x < 0.001
-
- def improve(guess: Double) =
- (guess + x / guess) / 2
-
- sqrtIter(1.0)
- }
-
- println(sqrt(2))
- println(sqrt(0.001))
- println(sqrt(0.1e-20))
- println(sqrt(1.0e20))
- println(sqrt(1.0e50))
-
-}