Optimizing Memory Allocation in a Simple, but Long Function
Peter Otten
__peter__ at web.de
Mon Apr 25 04:16:24 EDT 2016
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.
More information about the Python-list
mailing list