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


Groups > comp.lang.python > #12813

Re: Floating point multiplication in python

References <3348A754-2874-4E18-9E90-F9DB131E6AA0@163.com>
Date 2011-09-05 23:18 -0700
Subject Re: Floating point multiplication in python
From Chris Rebert <clp2@rebertia.com>
Newsgroups comp.lang.python
Message-ID <mailman.791.1315289913.27778.python-list@python.org> (permalink)

Show all headers | 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