X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2Fscl%2FRandom1.scl;h=4506a8a4f8f279a5b607e75700b9a903655dde1e;hp=66922eadb2f2a41c10e82e06b99592268ed52f54;hb=HEAD;hpb=dcca7344e1da6f975859fd79fbc6cead7d363042 diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Random1.scl b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Random1.scl index 66922eadb..4506a8a4f 100644 --- a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Random1.scl +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/scl/Random1.scl @@ -1,19 +1,19 @@ -import "StandardLibrary" - -// Actual program - -"""This function returns either 0 or 1 such that -the expected value is pi/4""" -approximatePi :: () -> Double -approximatePi () = if x*x + y*y < 1 then 1 else 0 - where - x = randomDouble - y = randomDouble - -averageOfNRepeats n f = sum [f () | n <- [1..n]] / fromInteger n - -betterApproximatePi () = averageOfNRepeats 1000 approximatePi * 4 - -main = withSeed 13 (betterApproximatePi ()) --- +import "StandardLibrary" + +// Actual program + +"""This function returns either 0 or 1 such that +the expected value is pi/4""" +approximatePi :: () -> Double +approximatePi () = if x*x + y*y < 1 then 1 else 0 + where + x = randomDouble + y = randomDouble + +averageOfNRepeats n f = sum [f () | n <- [1..n]] / fromInteger n + +betterApproximatePi () = averageOfNRepeats 1000 approximatePi * 4 + +main = withSeed 13 (betterApproximatePi ()) +-- 3.068 \ No newline at end of file