Am 02.01.2016 um 22:57 schrieb Chris Angelico:
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).
Well, honestly, I trusted my math and didn't thought much about the
technical limitations.
I only tried values from 1 to 100 and then again 12345, I believe, to
test the algorithm.
> 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. :)
When I find more time I take a closer look at it. Thank you (and
Bernardo) for your clarification. I hope everyone who read my article
reads yours, too and learns from it. ;-)
--
Robin Koch
--
https://mail.python.org/mailman/listinfo/python-list