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


Groups > comp.lang.python > #71676

Bug in Decimal??

Date 2014-05-17 13:01 +0200
From Stefan Krah <stefan-usenet@bytereef.org>
Subject Bug in Decimal??
Newsgroups comp.lang.python
Message-ID <mailman.10079.1400324487.18130.python-list@python.org> (permalink)

Show all headers | View raw


> 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


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web