summaryrefslogtreecommitdiffstats
path: root/Scala/sandbox/sqrt.scala
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-04-03 23:41:42 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2016-11-10 18:03:22 +0100
commitdadc875c05c830d15ee0aebea70aefaea6d3e55e (patch)
tree5e86616033f1cb49749d45ecc33021b99beec97f /Scala/sandbox/sqrt.scala
parent1242f3e674a2dc1b2a6d4a6597c0d72d0596f469 (diff)
downloadcoursera-dadc875c05c830d15ee0aebea70aefaea6d3e55e.zip
coursera-dadc875c05c830d15ee0aebea70aefaea6d3e55e.tar.gz
Scala : rename files in sandbox
Diffstat (limited to 'Scala/sandbox/sqrt.scala')
-rw-r--r--Scala/sandbox/sqrt.scala30
1 files changed, 0 insertions, 30 deletions
diff --git a/Scala/sandbox/sqrt.scala b/Scala/sandbox/sqrt.scala
deleted file mode 100644
index c76ee00..0000000
--- a/Scala/sandbox/sqrt.scala
+++ /dev/null
@@ -1,30 +0,0 @@
-
-object Sqrt {
-
- 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)
- }
-
- def run = {
- println("Sqrt")
- println(sqrt(2))
- println(sqrt(0.001))
- println(sqrt(0.1e-20))
- println(sqrt(1.0e20))
- println(sqrt(1.0e50))
- }
-
-}