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


Groups > comp.lang.python > #70908

Re: Bug in Decimal??

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'output': 0.05; 'skip:` 10': 0.07; 'expected.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'bug': 0.12; 'exactly,': 0.16; 'expecting': 0.16; 'message-id:@post.gmane.org': 0.16; 'propagation': 0.16; 'range,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'module': 0.19; 'header:User-Agent:1': 0.23; 'error': 0.23; 'skip:` 20': 0.24; 'certain': 0.27; 'header:X-Complaints-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'absolute': 0.30; 'compared': 0.30; 'too.': 0.31; '-0700,': 0.31; 'decimal': 0.31; "we're": 0.32; 'skip:d 20': 0.34; 'but': 0.35; 'library.': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; "you're": 0.61; 'more': 0.64; 'close': 0.67; 'believe': 0.68; 'natural': 0.68; 'results': 0.69; 'partial': 0.84; 'received:86': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Dickinson <mdickinson@enthought.com>
Subject Re: Bug in Decimal??
Date Sun, 4 May 2014 10:53:06 +0000 (UTC)
References <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host sea.gmane.org
User-Agent Loom/3.14 (http://gmane.org/)
X-Loom-IP 86.30.244.11 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9672.1399200803.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1399200803 news.xs4all.nl 2952 [2001:888:2000:d::a6]:34665
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:70908

Show key headers only | View raw


On Tue, 29 Apr 2014 19:37:17 -0700, pleasedontspam wrote:

> 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.

I had a quick look: this isn't a bug - it's just the result of propagation of
the error in "partial" to "final".

In more detail: we've got a working precision of 2016 significant figures.  For
any small x, we have (1 + x) / (1 - x) = 1 + 2x + 2x^2 + 2x^3 + ....  For your
value of x, `Decimal('1e-1007'), we've got enough precision to store
1 + 2x + 2x^2 exactly, but that's all.

So partial has an absolute error of around 2x^3, or 2e-3021.

And since the derivative of the natural log function is almost exactly 1 at the
point we're interested in, we expect the absolute error in the output to be
close to 2e-3021, too.

And that's *precisely* what you're seeing: the Decimal module is giving you a
result that's exactly `Decimal('2e-1007') - Decimal('1.3e-3021')`, while the
result you were expecting is `Decimal('2e-1007') + Decimal('0.7e-3021')`.  A
difference of exactly `Decimal('2e-3021')`, as expected.

-- 
Mark

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


Thread

Bug in Decimal?? pleasedontspam@isp.com - 2014-04-29 19:37 -0700
  Re: Bug in Decimal?? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-30 03:39 +0000
    Re: Bug in Decimal?? pleasedontspam@isp.com - 2014-04-30 05:01 -0700
    Re: Bug in Decimal?? pleasedontspam@isp.com - 2014-04-30 05:13 -0700
  Re: Bug in Decimal?? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-30 19:59 +1200
  Re: Bug in Decimal?? Mark Dickinson <mdickinson@enthought.com> - 2014-05-04 10:53 +0000
    Re: Bug in Decimal?? pleasedontspam@isp.com - 2014-05-15 13:45 -0700
      Re: Bug in Decimal?? Mark H Harris <harrismh777@gmail.com> - 2014-05-15 16:26 -0500
      Re: Bug in Decimal?? Mark Dickinson <mdickinson@enthought.com> - 2014-05-19 16:10 +0000

csiph-web