Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70908
| From | Mark Dickinson <mdickinson@enthought.com> |
|---|---|
| Subject | Re: Bug in Decimal?? |
| Date | 2014-05-04 10:53 +0000 |
| References | <973d2677-03c6-464a-8c88-f07282806468@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9672.1399200803.18130.python-list@python.org> (permalink) |
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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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