From 85a93fa145aaef49d434d05903310a9e5170affa Mon Sep 17 00:00:00 2001 From: paltherr Date: Fri, 18 Jul 2003 08:04:29 +0000 Subject: - Removed duplicates --- test/files/pos/cours2c.scala | 57 -------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 test/files/pos/cours2c.scala (limited to 'test/files/pos/cours2c.scala') diff --git a/test/files/pos/cours2c.scala b/test/files/pos/cours2c.scala deleted file mode 100644 index e3917e43eb..0000000000 --- a/test/files/pos/cours2c.scala +++ /dev/null @@ -1,57 +0,0 @@ -object m1 { - - def average(x: Double, y: Double) = (x + y)/2; - def abs(x: Double): Double = if (x < 0) - x else x; - def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < 0.001; - - def search(f: Double => Double, negPoint: Double, posPoint: Double): Double = { - val midPoint = average(negPoint, posPoint); - if (isCloseEnough(negPoint, posPoint)) - midPoint - else { - val testVal = f(midPoint); - if (testVal > 0) search (f, negPoint, midPoint) - else if (testVal < 0) search (f, midPoint, posPoint) - else midPoint - } - } - - def halfIntervalMethod(f: Double => Double, a: Double, b: Double): Double = { - val aval = f(a); - val bval = f(b); - if (aval < 0 && bval > 0) search(f, a, b) - else if (bval < 0 && aval > 0) search(f, b, a) - else error("Values are not of opposite sign") - } -} - -object m2 { - - def abs(x: Double): Double = if (x < 0) - x else x; - def isCloseEnough(x: Double, y: Double) = abs((x - y) / x) < 0.001; - def average(x: Double, y: Double) = (x + y)/2; - - def fixedPoint(f: Double => Double, firstGuess: Double) = { - def Try(guess: Double): Double = { - val next = f(guess); - if (isCloseEnough(guess, next)) next - else Try(next) - } - Try(firstGuess); - } - - def sin(x: Double): Double = x; - def cos(x: Double): Double = x; - - val result = fixedPoint((y => sin(y) + cos(y)), 1.0); - - def averageDamp(f: Double => Double)(x: Double) = - average(x, f(x)); - - def sqrt(x: Double) = - fixedPoint(averageDamp(y => x/y), 1.0); - - def cubeRoot(x: Double) = - fixedPoint(averageDamp(y => x/(y*y)), 1.0); -} - -- cgit v1.2.3