<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=KOI8-R" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Kostis Sagonas wrote:
<blockquote cite="mid200603250847.k2P8lBfH007162@spikklubban.it.uu.se"
 type="cite">
  <pre wrap="">Nick Linter wrote:

An example would have helped us understand better what the issue is.
Currently, I get:

Eshell V5.5  (abort with ^G)
1> math:log(...).
480.407</pre>
</blockquote>
Well, I get the following result:<br>
<blockquote><tt>43> math:log10(test:fib(1476)).
</tt><br>
  <tt>308.116
</tt><br>
  <tt>44> math:log10(</tt><tt>test</tt><tt>:fib(1477)).
</tt><br>
  <tt>š</tt><br>
  <tt>=ERROR REPORT==== 27-Mar-2006::10:57:47 ===
</tt><br>
  <tt>Error in process <0.181.0> with exit value:
{badarith,[{math,log10,[16#00012D269
</tt><br>
  <tt>C3FA9D767CB55B0DDF8E6A2DE7B1D967FF8D0BE61EB16ACD02D1A53C95A370ABD95285998D226919

</tt><br>
  <tt>D95DCA54298D92C348C27E635E1690E7858060F0DC14E885F0217413C55A1F820D6EB051F87C7C73

</tt><br>
  <tt>818AC23E4A9A00A2072C08C6697A2FAD66FC7DEBEEB7A5F582D7639A431B9C99CEC6315A9ED1C652

</tt><br>
  <tt>A81A6B59A39]},{erl_eval,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}

</tt><br>
  <tt>š</tt><br>
  <tt>** exited: {badarith,[{math,log10,
</tt><br>
  <tt>ššššššššššššššššššššššššššš
[211475298697902185255785861961179135570552502746803
</tt><br>
  <tt>25217495622655863402432394766663713782393252439761186467156621190833026337742520

</tt><br>
  <tt>45520741882086869936691237540043402509431087092122991804222930097654049305082429

</tt><br>
  <tt>75773774612140021599477983006713536106549441161323499077298115887067363710153036

</tt><br>
  <tt>315849480388057657]},
</tt><br>
  <tt>ššššššššššššššššššššš {erl_eval,do_apply,5},
</tt><br>
  <tt>ššššššššššššššššššššš {shell,exprs,6},
</tt><br>
  <tt>ššššššššššššššššššššš {shell,eval_loop,3}]} **
</tt><br>
</blockquote>
My system is Windows XP, Erlang R10B.
<blockquote cite="mid200603250847.k2P8lBfH007162@spikklubban.it.uu.se"
 type="cite">
  <pre wrap="">
fib(N) ->
  trunc((1/sqrt(5)) * (pow(((1+sqrt(5))/2),N) - pow(((1-sqrt(5))/2),N))).
  </pre>
</blockquote>
Good solution :-)<br>
Now I also have different idea without using recursion. It is based on
the following equation<br>
<tt>[F_nš ]šš [1š 1]šš [F_n-1]<br>
[šššš ] = [ššš ] * [šššš ]<br>
[F_n-1]šš [1š 0]šš [F_n-2]<br>
</tt>And we just have to calculate k-th power of the matrix
[[1,1],[1,0]]. It is possible to do within O(log(k)).<br>
<br>
<blockquote cite="mid200603250847.k2P8lBfH007162@spikklubban.it.uu.se"
 type="cite">
  <pre wrap="">PS. The performance you are experiencing in your version of fib/1
    has nothing to do with tail recursion...</pre>
</blockquote>
Yes, exponential number of recursive calls... Thank you.<br>
<br>
I'm sorry, but most interesting question (2nd, about number of digits
in an integer) remains unanswered. But I guess it is very rare problem
with numbers, so if there is no answer, I will understand.<br>
<br>
Best regards,<br>
Linker Nick.<br>
</body>
</html>