Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12814 > unrolled thread
| Started by | Gary Herron <gherron@islandtraining.com> |
|---|---|
| First post | 2011-09-06 00:00 -0700 |
| Last post | 2011-09-06 08:30 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Floating point multiplication in python Gary Herron <gherron@islandtraining.com> - 2011-09-06 00:00 -0700
Re: Floating point multiplication in python Duncan Booth <duncan.booth@invalid.invalid> - 2011-09-06 08:30 +0000
| From | Gary Herron <gherron@islandtraining.com> |
|---|---|
| Date | 2011-09-06 00:00 -0700 |
| Subject | Re: Floating point multiplication in python |
| Message-ID | <mailman.792.1315292754.27778.python-list@python.org> |
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
[toc] | [next] | [standalone]
| From | Duncan Booth <duncan.booth@invalid.invalid> |
|---|---|
| Date | 2011-09-06 08:30 +0000 |
| Message-ID | <Xns9F5860481F813duncanbooth@127.0.0.1> |
| In reply to | #12814 |
Gary Herron <gherron@islandtraining.com> wrote: > (But try: > print 1.1*1.1 > and see that the print statement does hide the roundoff error from you.) That varies according to the version of Python you are using. On my system: Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print(1.1*1.1) 1.21 >>> ^Z C:\Python27>cd \python32 C:\Python32>python Python 3.2.1 (default, Jul 10 2011, 21:51:15) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> print(1.1*1.1) 1.2100000000000002 -- Duncan Booth http://kupuguy.blogspot.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web