Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Trailing zeros of 100! Date: Sun, 3 Jan 2016 08:57:36 +1100 Lines: 27 Message-ID: References: <52ccbc4b-616b-4186-8802-97aaa5b0d9af@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de EkENQHKtoW6v50GUuDspwAmYWw6Q9d3ZVlAHGzcMoDLg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'float': 0.05; 'cc:addr:python-list': 0.09; 'integer,': 0.09; 'rounding': 0.09; 'work"': 0.09; 'jan': 0.11; '"should': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'multiples': 0.16; 'nearest': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'rounding.': 0.16; 'test".': 0.16; 'thereabouts.': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'trying': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'van': 0.26; 'message- id:@mail.gmail.com': 0.27; '(maybe': 0.29; 'normally': 0.30; 'operations': 0.31; "can't": 0.32; 'point': 0.33; 'worked': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'received:209': 0.38; 'log': 0.38; 'represent': 0.38; 'end': 0.39; 'why': 0.39; 'test': 0.39; 'does': 0.39; 'your': 0.60; 'between': 0.65; 'sound': 0.72; '"yes,': 0.84; '17:09': 0.84; 'calculations': 0.84; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=RkXziwOVO/CIBYuOS11rM1NHSGFkCl0d3tGwTBKduco=; b=uNwD/5VsKW7hI0EnlQSeM2dN4T6BqY8crrEmgDvPBiqT1LcPjo6wP/cpwdzk57MfrZ fN6Q5ApuEIsh4pY27cZG+wWJEWXGy8w1uSV3VSUakjBAYH3klM843A1QGvQvc95HkWnV CGaeb/pcutxUfxIgaByYAAcqBfD80KMuk15N3XRxVic9zzTrBadzqgoCgFW77IxcU3Gt YK/LVIQxJJWgvB5gwnMROsypozS34mWV0Z+d72IARrL5MrjuQAf/WqMbFke2KqrwhbXE 3REqkgKwwlo5vgLe2rc5+4pE8qJ6932jICBcogvwg+WB8Km6gyXGi3hTKSylo5WOm+FJ fS4g== X-Received: by 10.107.40.76 with SMTP id o73mr14667359ioo.157.1451771856849; Sat, 02 Jan 2016 13:57:36 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101173 On Sun, Jan 3, 2016 at 3:56 AM, Robin Koch 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