This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Type: bug in float arithmetic? behavior resolved Python 3.3
process
Status: Resolution: closed not a bug Rihards, zach.ware normal

Created on 2014-02-06 20:07 by Rihards, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg210412 - (view) Author: Rihards (Rihards) Date: 2014-02-06 20:07
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32
>>> 11.29-6.29
4.999999999999999
>>> 11.30-6.30
5.000000000000001
>>>
msg210413 - (view) Author: Zachary Ware (zach.ware) * Date: 2014-02-06 20:21
Hi Rihards,

This is not a bug, this is an example of the limitations of binary floating point arithmetic.  See http://docs.python.org/3/tutorial/floatingpoint.html for more information.  For explanation by demonstration, have a look at this:

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
>>> from decimal import Decimal as D
>>> D(11.29)
Decimal('11.28999999999999914734871708787977695465087890625')
>>> D(6.29)
Decimal('6.29000000000000003552713678800500929355621337890625')
>>> D(11.30)
Decimal('11.300000000000000710542735760100185871124267578125')
>>> D(6.30)
Decimal('6.29999999999999982236431605997495353221893310546875')
>>> D(11.291)
Decimal('11.291000000000000369482222595252096652984619140625')
>>> D(6.291)
Decimal('6.291000000000000369482222595252096652984619140625')
>>> 11.29 - 6.29
4.999999999999999
>>> 11.30 - 6.30
5.000000000000001
>>> 11.291 - 6.291
5.0
>>> D(11.29) - D(6.29)
Decimal('4.999999999999999111821580300')
>>> D(11.30) - D(6.30)
Decimal('5.000000000000000888178419700')
>>> D(11.291) - D(6.291)
Decimal('5.000000000000000000000000000')
>>>

For future reference, "bug?" isn't very useful as an issue title :).  The title should be as brief a summary of the possible bug as you can come up with, or at least mention which part(s) of Python are affected.
History
Date User Action Args