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


Groups > comp.lang.python > #107587

Re: Optimizing Memory Allocation in a Simple, but Long Function

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: Optimizing Memory Allocation in a Simple, but Long Function
Date 2016-04-25 10:16 +0200
Organization None
Message-ID <mailman.66.1461572195.32212.python-list@python.org> (permalink)
References (7 earlier) <CAHVvXxSwb8=a+b5WQfd3KeXTe8VuL4RMnwu3TSNp8129FJHJGw@mail.gmail.com> <CAGuRns911cXoppsS_8f657UDdCtVFhAzwY7ohafOqrsEuRq7vQ@mail.gmail.com> <CAGuRns9byxLC3pGrkPG8m-qLTzB1+PYxLHNy2=fOHcwWR21x6A@mail.gmail.com> <CAGuRns9yCR8FP9-wV5OYRKUHVtEVMsYgrtQtoB2Up-C4CTOkUw@mail.gmail.com> <nfkjop$tui$1@ger.gmane.org>

Show all headers | View raw


Derek Klinge wrote:

> I found that the pattern of an additional digit of accuracy corresponding
> to 10*n did not hold as strongly for that value (I can post data if
> desired). I also got some results that seem to contradict the mathematical
> definition. For example try EulersNumber(10**15).LimitMethod(), the
> definition places this limit at e, and yet the (python) answer is >3.035.
> Please let me know if I've fouled up the implementation somehow.

There's nothing wrong with the formula, but floating point numbers have 
limited precision. At some point your calculation will become mostly a 
rounding error.

You'll see the surprising

>>> n = 10**14
>>> (1+1/n)**n
2.716110034087023
>>> n = 10**15
>>> (1+1/n)**n
3.035035206549262

on most modern computers with most programming langagues.
 
https://docs.python.org/3.5/tutorial/floatingpoint.html

has some introductory information.

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


Thread

Re: Optimizing Memory Allocation in a Simple, but Long Function Peter Otten <__peter__@web.de> - 2016-04-25 10:16 +0200

csiph-web