[erlang-questions] what does when do here? fib(1200000) so slow, erlang cant handle big numbers?
Circular Function
circularfunc@REDACTED
Tue Jul 1 14:31:22 CEST 2008
what does when N>0 do here? seems like no difference.
and would you consider this good idiomatic erlang(ofc there is an even faster one that i found, posted at the end)?
also, this is linear right? so why does fib(1200000) never finsih?
erlang cant handle such big numbers? because 12000 is pretty much
instant and 120000 takes a second or so.
fib_i(A, _B, 0) -> A;
fib_i(A, B, N) when N > 0 -> fib_i(B, A + B, N - 1).
fib(N) -> fib_i(0, 1, N).
fib_i(A, _B, 0) -> A;
fib_i(A, B, N) -> fib_i(B, A + B, N - 1).
fib(N) -> fib_i(0, 1, N).
fibo3(0, _, Pair) -> Pair;
fibo3(N, {Fib1, Fib2}, Pair) when N rem 2 == 0 ->
SquareFib1 = Fib1*Fib1,
fibo3(N div 2, {2*Fib1*Fib2 - SquareFib1, SquareFib1 + Fib2*Fib2}, Pair);
fibo3(N, {FibA1, FibA2}=Pair, {FibB1, FibB2}) ->
fibo3(N-1, Pair, {FibA1*FibB2 + FibB1*(FibA2 - FibA1), FibA1*FibB1 + FibA2*FibB2}).
__________________________________________________________
Går det långsamt? Skaffa dig en snabbare bredbandsuppkoppling.
Sök och jämför priser hos Kelkoo.
http://www.kelkoo.se/c-100015813-bredband.html?partnerId=96914325
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080701/b3a1e271/attachment.htm>
More information about the erlang-questions
mailing list