Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'example:': 0.03; 'widely': 0.05; 'intermediate': 0.07; 'differently.': 0.09; 'mostly': 0.14; '754': 0.16; 'behave': 0.16; 'precision.': 0.16; 'skip:d 130': 0.16; 'language': 0.16; 'stefan': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'pass': 0.26; 'skip:p 30': 0.29; 'list:': 0.30; 'decimal': 0.31; 'follows': 0.31; 'received:78.46': 0.31; 'test': 0.35; 'but': 0.35; 'charset:us-ascii': 0.36; "i'll": 0.36; 'too': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'content- disposition:inline': 0.62; 'increase': 0.74; 'digits?': 0.84; 'serious': 0.97 Date: Sat, 17 May 2014 13:01:25 +0200 From: Stefan Krah To: python-list@python.org Subject: Bug in Decimal?? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400324487 news.xs4all.nl 2897 [2001:888:2000:d::a6]:36506 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71676 > 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