
Daniel, Stephen, Felipe thanks for Your answers/advice, which I
studied this morning. Helps me a lot on my learning curve. I guess it
takes some time to get a feeling for the performance/runtime behaviour
of abstractions in Haskell.
Just for fun and w/o knowing Lua: I translated my Haskell
"loops-while"-version into Lua and ran on LuaJit Beta 2.0.0. Seems to
beat our best Haskell version.
print("EPS: ")
EPS = io.read("*number")
pi2 = 1
i = 3
s = false
repeat
pi1 = pi2
if s then
pi2 = pi1 + 1.0/i
s = false
else
pi2 = pi1 - 1.0/i
s = true
end
i = i+2
until EPS > 4.0 * math.abs(pi2-pi1)
print("PI mit EPS", EPS," = ",4*pi1," n= ",(i-3)/2)
-- Markus
On Sun, Jan 31, 2010 at 9:43 PM, Daniel Fischer
Am Sonntag 31 Januar 2010 20:22:56 schrieb Stephen Tetley:
On my machine, they diverged at the eighth decimal place -
Leibniz4 3.1415926526069526 Leibniz1 3.1415926445727678
Ah, that. I thought you were talking about timings.
There are several things that can lead to differing results here,
1) order of summation (I think only my loop had a different order) 2) due to different tests, it might happen that one algorithm evaluates one term more than the other 3) are intermediate results truncated to 64 bits or kept in an 80-bit register?
I'm astonished by the size of the difference, though.
But if you sum from small to large, the results are very accurately the theoretically expected results, so I think it's 1) together with 3) which make the difference. _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners