Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news2.arglkargh.de!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.049 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'received:66.35': 0.07; 'python': 0.08; '>>>>': 0.09; 'subject:python': 0.11; '*any*': 0.16; '1.1': 0.16; 'wrote:': 0.16; '(but': 0.21; 'header:In-Reply- To:1': 0.22; 'all:': 0.23; 'pm,': 0.24; 'statement': 0.25; 'print': 0.29; 'arithmetic': 0.30; 'error': 0.32; 'does': 0.32; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'try:': 0.34; 'subject:skip:m 10': 0.37; 'but': 0.37; 'allows': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'why': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'computer.': 0.40; 'more': 0.60; 'skip:1 10': 0.63; '1.21': 0.84; '10:57': 0.84; 'you.)': 0.91 Date: Tue, 06 Sep 2011 00:00:39 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Floating point multiplication in python References: <3348A754-2874-4E18-9E90-F9DB131E6AA0@163.com> In-Reply-To: <3348A754-2874-4E18-9E90-F9DB131E6AA0@163.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1315292754 news.xs4all.nl 2483 [2001:888:2000:d::a6]:53733 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12814 On 09/05/2011 10:57 PM, xyz 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? Who can tell me where's the 0.0000000000000002 from? It's not a python error It's the nature of floating point arithmetic to be inaccurate on *ANY* computer. Python just allows you to see the inaccuracies. (But try: print 1.1*1.1 and see that the print statement does hide the roundoff error from you.) Read this for more info: http://pyfaq.infogami.com/why-are-floating-point-calculations-so-inaccurate