Zachary Ware added the comment:

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
Type "help", "copyright", "credits" or "license" for more information.
>>> 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.

----------
nosy: +zach.ware
resolution:  -> invalid
stage:  -> committed/rejected
status: open -> closed
title: bug? -> bug in float arithmetic?
type:  -> behavior
versions: +Python 3.3

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue20533>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to