Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73474
| 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 | <rosuav@gmail.com> |
| 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 | <XnsA35313E634BA0fraserlonggmailcom34@216.196.109.145> |
| References | <XnsA35313E634BA0fraserlonggmailcom34@216.196.109.145> |
| Date | Sat, 21 Jun 2014 11:33:25 +1000 |
| Subject | Re: python 3.44 float addition bug? |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.11177.1403314412.18130.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Sat, Jun 21, 2014 at 10:57 AM, FraserL
<fraser.long+usenet@nospamgmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
python 3.44 float addition bug? FraserL <fraser.long+usenet@NOSPAMgmail.com> - 2014-06-20 19:57 -0500
Re: python 3.44 float addition bug? FraserL <fraser.long+usenet@gmail.com> - 2014-06-20 20:11 -0500
Re: python 3.44 float addition bug? Gary Herron <gary.herron@islandtraining.com> - 2014-06-20 18:19 -0700
Re: python 3.44 float addition bug? Gary Herron <gary.herron@islandtraining.com> - 2014-06-20 18:07 -0700
Re: python 3.44 float addition bug? Chris Angelico <rosuav@gmail.com> - 2014-06-21 11:33 +1000
Re: python 3.44 float addition bug? INADA Naoki <songofacandy@gmail.com> - 2014-06-21 10:06 +0900
Re: python 3.44 float addition bug? Grant Edwards <invalid@invalid.invalid> - 2014-06-21 14:25 +0000
Re: python 3.44 float addition bug? Ned Deily <nad@acm.org> - 2014-06-21 12:24 -0700
Re: python 3.44 float addition bug? buck <workitharder@gmail.com> - 2014-06-23 17:55 -0700
Re: python 3.44 float addition bug? Chris Angelico <rosuav@gmail.com> - 2014-06-24 13:26 +1000
Re: python 3.44 float addition bug? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-06-24 17:30 +1200
Re: python 3.44 float addition bug? Steven D'Aprano <steve@pearwood.info> - 2014-06-24 06:34 +0000
Re: python 3.44 float addition bug? Maciej Dziardziel <fiedzia@gmail.com> - 2014-06-25 14:12 -0700
Re: python 3.44 float addition bug? Steven D'Aprano <steve@pearwood.info> - 2014-06-26 02:56 +0000
Re: python 3.44 float addition bug? Chris Angelico <rosuav@gmail.com> - 2014-06-26 13:13 +1000
Re: python 3.44 float addition bug? Steven D'Aprano <steve@pearwood.info> - 2014-06-26 04:17 +0000
Re: python 3.44 float addition bug? Chris Angelico <rosuav@gmail.com> - 2014-06-26 14:41 +1000
Re: python 3.44 float addition bug? Ben Finney <ben@benfinney.id.au> - 2014-06-26 13:39 +1000
Re: python 3.44 float addition bug? Steven D'Aprano <steve@pearwood.info> - 2014-06-26 09:15 +0000
Re: python 3.44 float addition bug? Chris Angelico <rosuav@gmail.com> - 2014-06-26 19:38 +1000
Re: python 3.44 float addition bug? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-27 02:51 +0000
Re: python 3.44 float addition bug? Chris Angelico <rosuav@gmail.com> - 2014-06-27 13:24 +1000
Re: python 3.44 float addition bug? Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-27 10:18 -0600
Re: python 3.44 float addition bug? Stefan Behnel <stefan_ml@behnel.de> - 2014-06-26 07:53 +0200
csiph-web