Re: Computer Language Shootout
I fixed the partial-sums example. There were a few errors and I changed the meat
of the program to match the FreeBASIC version. Multiplications should be faster
than powers.
I get the proper output but I haven't tested timing yet.
-- partial-sums benchmark (for the Great Programming Shootout)
-- By András Szabó 2007 and Matt Lewis
-- This code is public domain code. You may reuse, redistribute or modify it
-- however you wish.
--
-- about the partial-sums benchmark
-- diff program output N = 25000 with this output file to check your program is
-- correct before contributing.
-- (Programs may use a single-loop or several-loops; programs may cache
recomputed
-- values in local variables)
-- Each program should use the same naive iterative double-precision algorithms
to
-- calculate partial-sums of the series.
without trace
without warning
without profile
include get.e
sequence argv
object N
argv = command_line()
if length(argv) > 2 then
N = value(argv[3])
N = N[2]
else
N = 0
end if
atom res1, res2, res3, res4, res5, res6, res7, res8, res9
res1 = 0.0
res2 = 0.0
res3 = 0.0
res4 = 0.0
res5 = 0.0
res6 = 0.0
res7 = 0.0
res8 = 0.0
res9 = 0.0
atom temp
atom k2, k3, ksin, kcos, alt
constant tt = 2/3
alt = 1.0
for k=1 to N by 1 do
k2 = k * k
k3 = k2 * k
ksin = sin(k)
kcos = cos(k)
res1 += power(tt, k-1)
res2 += power(k, -0.5)
res3 += 1 / (k * (k + 1))
res4 += 1 / (k3 * ksin * ksin)
res5 += 1 / (k3 * kcos * kcos)
res6 += 1 / k
res7 += 1 / k2
res8 += alt / k
res9 += alt / (2 * k - 1)
alt *= -1
end for
printf(1,"%.9f\t(2/3)^k",res1)
printf(1,"\n%.9f\tk^-0.5",res2)
printf(1,"\n%.9f\t1/k(k+1)",res3)
printf(1,"\n%.9f\tFlint Hills",res4)
printf(1,"\n%.9f\tCookson Hills",res5)
printf(1,"\n%.9f\tHarmonic",res6)
printf(1,"\n%.9f\tRiemann Zeta",res7)
printf(1,"\n%.9f\tAlternating Harmonic",res8)
printf(1,"\n%.9f\tGregory",res9)
--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.
|
Not Categorized, Please Help
|
|