Hello,
I believe I found a bug in the Decimal library. The natural logarithm results 
seem to be off in a certain range, as compared with Wolfram Alpha.

Here's an example:

from decimal import *
getcontext().prec=2016
one=Decimal(1)
number=Decimal('1e-1007')

partial=(one+number)/(one-number)

final.ln()


The result should be 2.00000... with all zeroes and 7 at the end. Instead, I'm 
getting 1.999999.. with 2 digits different at the end.

I checked that this happens for any 1e-N with N relatively large (above about 
300 it starts showing bad digits at the end. 
Set the precision even higher and you'll see more digits off, it seems for 
number=10^-N, the error begins around 10^(-2N). The partial result (1+x)/(1-x) 
is correct to the number of digits specified, so it seems ln() is having 
accuracy problems.

Can other people confirm this or is it just my imagination? I tested with 
python 2.7.5 in XUbuntu, and also with my own build of mpdecimal 2.4.0 (latest, 
built from source). I compared the results with wolfram Alpha, and also with an 
open source arbitrary precision calculator, which matches Alpha results.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to