Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71676 > unrolled thread

Bug in Decimal??

Started byStefan Krah <stefan-usenet@bytereef.org>
First post2014-05-17 13:01 +0200
Last post2014-05-17 13:01 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Bug in Decimal?? Stefan Krah <stefan-usenet@bytereef.org> - 2014-05-17 13:01 +0200

#71676 — Bug in Decimal??

FromStefan Krah <stefan-usenet@bytereef.org>
Date2014-05-17 13:01 +0200
SubjectBug in Decimal??
Message-ID<mailman.10079.1400324487.18130.python-list@python.org>
> I'll follow up directly with the author of mpdecimal, as this is
> somewhat serious on a language that's so widely used as python.

> But please test it and confirm, am I seeing ghost digits?

This has already been settled on libmpdec-devel, but for the list:

As Mark Dickinson has already explained, you need to increase the intermediate
precision. For example:

>>> from decimal import *
>>> getcontext().prec=4000
>>> one=Decimal(1)
>>> number=Decimal('1e-1007')
>>> partial=(one+number)/(one-number)
>>> getcontext().prec=2016
>>> partial.ln()
Decimal('2.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000007E-1007')


Otherwise 'partial' has an error that is too large when you pass it to
the ln() function.  Since decimal mostly follows IEEE 754 with arbitrary
precision extensions, it cannot behave differently.


Stefan Krah


[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web