[Openmcl-devel] Numerical precision lacking for log (base 10)
Sudhir Shenoy
sshenoy at gol.com
Tue Jan 26 18:44:48 PST 2010
Hi,
In the course of solving a Project Euler problem (#104), I was trying
to compute the first 9 digits of large Fibonacci numbers and could not
find an answer (the same code worked in SBCL). The reason seems to be
that CCL does not have an accurate log function.
Specifically, in CCL (on both ppc and intel), "(log (sqrt 5.0d0) 10)"
returns 0.34948499731479665D0 whereas SBCL returns
0.34948500216800943d0 (this agrees with my desk calculator). The
difference in the two seems to be that in the implementation of log,
CCL is using natural logarithms and SBCL is using logarithms to base
2. Is this difference the reason for the discrepancies (precision loss
after the 6th decimal) or is the CCL numerical algorithm not the best?
Single precision seems to work much better in these computations in
CCL (mostly agrees with SBCL except for some numbers such as 2/3).
Cheers
Sudhir
BTW, I tried other numbers and find the same precision loss, e.g.
No. CCL SBCL
PI 0.4971498657903351D0 0.49714987269413385d0
sqrt(10) 0.4999999930566223D0 0.5d0
E 0.4342944758723105D0 0.43429448190325176d0
2/3 -0.17609124 -0.17609125
More information about the Openmcl-devel
mailing list