On Sun, Jan 3, 2016 at 3:56 AM, Robin Koch <robin.k...@t-online.de> wrote: > Am 02.01.2016 um 17:09 schrieb Tony van der Hoff: >> >> On 02/01/16 16:57, Robin Koch wrote: >>> >>> sum([int(0.2**k*n) for k in range(1, int(log(n, 5))+1)]) >> >> >> But did you actually test it? > > > Yes, should work for n >= 1. > > Why do you ask?
Your "should work" does not sound good as a response to "actually test". Normally I would expect the response to be "Yes, and it worked for me" (maybe with a log of an interactive session). Floating point can't represent every integer, and above 2**53 you end up able to represent only those which are multiples of ever-increasing powers of two; 100! is between 2**524 and 2**525, so any float operations are going to be rounding off to the nearest 2**471 or thereabouts. That's... a lot of rounding. That's like trying to calculate whether pi is rational, but basing your calculations on the approximation 3.14. :) ChrisA -- https://mail.python.org/mailman/listinfo/python-list