Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12813

Re: Floating point multiplication in python

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'python': 0.08; '>>>>': 0.09; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; 'subject:python': 0.11; 'binary': 0.13; '1.1': 0.16; 'arithmetic.': 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'wrote:': 0.16; 'cheers,': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'all:': 0.23; 'sep': 0.23; 'pm,': 0.24; "python's": 0.24; 'message-id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.30; 'equivalent': 0.31; 'chris': 0.32; 'fault': 0.34; 'rather': 0.35; 'received:209.85.160': 0.35; 'url:python': 0.36; 'subject:skip:m 10': 0.37; 'languages': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'why': 0.39; "it's": 0.40; 'skip:1 10': 0.63; '1.21': 0.84; '10:57': 0.84; 'sender:addr:chris': 0.84; 'to:none': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=hzoyDasl1EAZzNLCOuHXHMKO7KTIiGhTIpN5Fi463hg=; b=KUZ1crtlmO6GVhDckzYtACRraRwQRyGM2o9rceP/C2qrxxb2MNNbjMuWmfBKAOoqaF 8ztmmyvc6Ae2o+HoyzjlYNAzG4kpsZ66uKkTz9lqEly1yVeF+QNgvEpiLFN9NI+9bifa p33MM+wvY8of72/54c3ZpHkPpI+rHQh2DBSDE=
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <3348A754-2874-4E18-9E90-F9DB131E6AA0@163.com>
References <3348A754-2874-4E18-9E90-F9DB131E6AA0@163.com>
Date Mon, 5 Sep 2011 23:18:30 -0700
X-Google-Sender-Auth TBLBHuPQAO84_oww6jOvQIrZiI8
Subject Re: Floating point multiplication in python
From Chris Rebert <clp2@rebertia.com>
Cc python-list@python.org
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.791.1315289913.27778.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1315289913 news.xs4all.nl 2504 [2001:888:2000:d::a6]:49600
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:12813

Show key headers only | View raw


On Mon, Sep 5, 2011 at 10:57 PM, xyz <xyzhtml@163.com> wrote:
> hi all:
>
> As we know ,  1.1 * 1.1 is 1.21 .
> But in python ,I got following :
>
>>>> 1.1 * 1.1
> 1.2100000000000002
>
> why python get wrong result?

It's not Python's fault per se, rather it's the inherent nature of
binary floating-point arithmetic. Try the equivalent in most other
languages and you'll get the same "error".
Please read http://docs.python.org/tutorial/floatingpoint.html

Cheers,
Chris

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Floating point multiplication in python Chris Rebert <clp2@rebertia.com> - 2011-09-05 23:18 -0700

csiph-web