From 63357fe3a8b1f30d224a3180912704aa35cf2089 Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Fri, 8 Apr 2011 16:40:41 +1200 Subject: [PATCH] Small fix to make tailrec pi the same as other implementations --- akka-tutorials/akka-tutorial-first/src/main/scala/Pi.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/akka-tutorials/akka-tutorial-first/src/main/scala/Pi.scala b/akka-tutorials/akka-tutorial-first/src/main/scala/Pi.scala index d644518431..45b0ddd89a 100644 --- a/akka-tutorials/akka-tutorial-first/src/main/scala/Pi.scala +++ b/akka-tutorials/akka-tutorial-first/src/main/scala/Pi.scala @@ -73,7 +73,7 @@ object Pi extends App { def calculatePiFor(arg: Int, nrOfElements: Int): Double = { val end = (arg + 1) * nrOfElements - 1 @tailrec def doCalculatePiFor(cursor: Int, acc: Double): Double = { - if (end == cursor) acc + if (cursor > end) acc else doCalculatePiFor(cursor + 1, acc + (4 * math.pow(-1, cursor) / (2 * cursor + 1))) } doCalculatePiFor(arg * nrOfElements, 0.0D)