Sat Mar 25 09:47:11 CET 2006
Nick Linter wrote:
> I was playing with Erlang for calculation over large numbers and
> discovered some issues:
> 1. math:log fails with "badarg" for big integers.
An example would have helped us understand better what the issue is.
Currently, I get:
Eshell V5.5 (abort with ^G)
> 3. Let me define the following function:
> fib(0) -> 0;
> fib(1) -> 1;
> fib(N) -> fib(N-1) + fib(N-2).
> I have failed to convert this function _without_ put/get to be able to
> compute even fib(100) within reasonable period of time (I guess I did it
> wrong so that tail recursion was not here). Is there a way to compute
> fib(N), N>=100 without side effects?
-import(math, [pow/3, sqrt/1]).
trunc((1/sqrt(5)) * (pow(((1+sqrt(5))/2),N) - pow(((1-sqrt(5))/2),N))).
PS. The performance you are experiencing in your version of fib/1
has nothing to do with tail recursion...
More information about the erlang-questions