Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107646
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Optimizing Memory Allocation in a Simple, but Long Function |
| Date | 2016-04-26 10:54 +0100 |
| Message-ID | <mailman.101.1461664511.32212.python-list@python.org> (permalink) |
| References | (10 earlier) <mailman.63.1461553965.32212.python-list@python.org> <do5vu5Fipb4U1@mid.individual.net> <CAHVvXxTU2k74S_hG=RtsEx=5uTk34Ppf4t2PhqBsat39Kv3ihQ@mail.gmail.com> <CAGuRns9w1bdScXdnhhD_COKftVaRm48y+RFMsCrBWF=mJcKnbw@mail.gmail.com> <CAHVvXxS5eTsrwGb65DpRxZ0bYDUVvt26Q5h2Arevm8zDRNKNaA@mail.gmail.com> |
On 25 April 2016 at 15:35, Derek Klinge <schilke.60@gmail.com> wrote:
>
> Although I see the value of relative error, I am just as interested in
> absolute error (though admittedly they are directly related values).
I was referring to relative error because the relative error is the
same at each step making the calculation of the global error easier.
> Are there modules or libraries I can/should use to minimize rounding error
> and use very large values of N and get an accurate answer?
from decimal import Decimal, localcontext
def e(prec):
with localcontext() as ctx:
ctx.prec = 2*prec + 1
N = Decimal(10)**(prec)
eapprox = (1 + 1/N)**N
ctx.prec = prec
return +eapprox
print(e(50))
Alternatively you can just use Decimal(1).exp().
> How does the math
> module calculate the vale of e?
https://hg.python.org/cpython/file/tip/Include/pymath.h#l54
--
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Optimizing Memory Allocation in a Simple, but Long Function Derek Klinge <schilke.60@gmail.com> - 2016-04-24 20:12 -0700
Re: Optimizing Memory Allocation in a Simple, but Long Function Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-04-25 19:39 +1200
Re: Optimizing Memory Allocation in a Simple, but Long Function Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-25 14:45 +0100
Re: Optimizing Memory Allocation in a Simple, but Long Function Derek Klinge <schilke.60@gmail.com> - 2016-04-25 14:35 +0000
Re: Optimizing Memory Allocation in a Simple, but Long Function Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-26 10:54 +0100
csiph-web