Title: wrong float plus/minus op result
Type: behavior Stage:
Components: Versions: Python 3.3
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Laurent.Fournier, brett.cannon
Priority: normal Keywords:

Created on 2013-08-01 12:01 by Laurent.Fournier, last changed 2013-08-01 12:48 by brett.cannon. This issue is now closed.

Messages (3)
msg194050 - (view) Author: Laurent Fournier (Laurent.Fournier) Date: 2013-08-01 12:01
Python 3.3.1 (with GCC 4.7.3) on Linux

print (.3-.1)
msg194053 - (view) Author: Laurent Fournier (Laurent.Fournier) Date: 2013-08-01 12:16
also with addition !

print (.05+.01)
msg194060 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2013-08-01 12:48
This is actually expected because that is just how floating point works in programming (see for all the gnarly details).

If you want exact decimal arithmetic, use the decimal module (which got significantly faster in Python 3.3)::

>>> import decimal
>>> decimal.Decimal('.3') - decimal.Decimal('.1')
>>> decimal.Decimal('.05') + decimal.Decimal('.01')
Date User Action Args
2013-08-01 12:48:51brett.cannonsetstatus: open -> closed

nosy: + brett.cannon
messages: + msg194060

resolution: not a bug
2013-08-01 12:16:30Laurent.Fourniersetmessages: + msg194053
title: wrong float minus op result -> wrong float plus/minus op result
2013-08-01 12:01:51Laurent.Fourniercreate