Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '21,': 0.07; 'subject:bug': 0.07; 'cc:addr:python-list': 0.11; '0.01': 0.16; 'be:': 0.16; 'bug:': 0.16; 'clues': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'str()': 0.16; 'subject:python': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'case,': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'two': 0.37; 'being': 0.38; 'sometimes': 0.38; 'how': 0.40; 'simply': 0.61; "you're": 0.61; "you've": 0.63; 'more': 0.64; 'cut': 0.74; 'seeing,': 0.84; 'info,': 0.91; 'to:none': 0.92 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=78gvg6oLGC/CGIq3SDrnTykCkPHZk9zafUMpUzs75l0=; b=JqI+hSoqkBdrNvAMvPHFLqR0fuyQ4tae3WFwuhb+cnL8lV5d+ApwcbxuyuNQRYXEmZ F95LUyrcUoTSLL9CQSRSkejTIeNHmpRCY7MpB+rL7xk5StgM+ZbLQgcKG0U1XW04OrSV v9r5FcDBuZdk3wenJqZgUaGEeaQTAjls3Pv7eAWqNUynIEWDbiimX8vMG9wB894m9rzs PZxi9Hq4d5BElIa/gDIgAGcw8s+fqe9Ai9c4cJbbFYokKhOoN4fi93VQp3+hSQGUi8HO 8Wg2ZMVfFUyZtveRdr/GDuzCrJHjJrFBkRcYbHKCVSACXzbgRn/KB6TmhrlaCjmuj9Ou 7vow== MIME-Version: 1.0 X-Received: by 10.194.58.199 with SMTP id t7mr8610059wjq.14.1403314405184; Fri, 20 Jun 2014 18:33:25 -0700 (PDT) In-Reply-To: References: Date: Sat, 21 Jun 2014 11:33:25 +1000 Subject: Re: python 3.44 float addition bug? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1403314412 news.xs4all.nl 2898 [2001:888:2000:d::a6]:37392 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73474 On Sat, Jun 21, 2014 at 10:57 AM, FraserL wrote: > #test code > z = 0.01 > p = 0.0 > for x, y in enumerate(range(1, 20)): > p += z > print(p) > #end General tip when you think you've found a bug: Cut out everything that isn't part of it. In this case, the enumerate has nothing to do with what you're seeing, which is an artifact of floating-point arithmetic, so a more classic loop header would simply be: for i in range(19): (Or some people will use _ to emphasize that the iterated-over values are being ignored.) The smaller you can make your test code, the more likely that people will be able to see what's going on. Also, when you're looking at how things print out, consider looking at two things: the str() and the repr(). Sometimes just "print(p)" doesn't give you all the info, so you might instead want to write your loop thus: z = 0.01 p = 0.0 for i in range(19): p += z print(str(p) + " -- " + repr(p)) Sometimes you can get extra clues that way, although in this instance I think you won't. ChrisA