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.

Title: Addition giving incorrect result in certain circumstances
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.5
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Aodhán Collins, r.david.murray, skrah
Priority: normal Keywords:

Created on 2017-09-12 19:56 by Aodhán Collins, last changed 2022-04-11 14:58 by admin. This issue is now closed.

File name Uploaded Description Edit
pythonbug.txt Aodhán Collins, 2017-09-12 19:56 Calculation Tests
Messages (3)
msg301991 - (view) Author: Aodhán Collins (Aodhán Collins) Date: 2017-09-12 19:56
Basic addition is dropping a tiny fraction when adding together certain numbers. We have discovered that when adding together the numbers 8.95 and 0.95 we get an incorrect answer, that is off by a tiny fraction. This doesn't occur when adding 7.95 and 0.95 but occurs for 8.95 and above. We have attached a file showing our calculations failing on Python 2.7 (on both a Mac and Linux system) and 3.5 (on a Linux system).
msg301992 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2017-09-12 20:17
Pythons has binary floating point, which does not give the same
results as a pocket calculator.

You can see the differences by using the decimal module:

# These are the binary floats in exact decimal representation.
>>> Decimal(7.95)
>>> Decimal(8.95)

# This is exact decimal arithmetic.
>>> Decimal("8.95") + Decimal("0.95")
msg301993 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-09-12 20:18
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75616
2017-09-12 20:18:08r.david.murraysetnosy: + r.david.murray
messages: + msg301993
2017-09-12 20:17:03skrahsetstatus: open -> closed

nosy: + skrah
messages: + msg301992

resolution: not a bug
stage: resolved
2017-09-12 19:56:01Aodhán Collinscreate