17 lines
457 B
Plaintext
17 lines
457 B
Plaintext
function fibonacci(integer n) -- iterative, works for -ve numbers
|
|
atom a=0, b=1
|
|
if n=0 then return 0 end if
|
|
if abs(n)>=79 then ?9/0 end if -- inaccuracies creep in above 78
|
|
for i=1 to abs(n)-1 do
|
|
{a,b} = {b,a+b}
|
|
end for
|
|
if n<0 and remainder(n,2)=0 then return -fcache[absn] end if
|
|
return fcache[absn]
|
|
end function
|
|
|
|
for i=0 to 28 do
|
|
if i then puts(1,", ") end if
|
|
printf(1,"%d", fibonacci(i))
|
|
end for
|
|
puts(1,"\n")
|