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: what is that result!?
Type: Stage:
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ezio.melotti, mark.dickinson, mrabarnett, niacdoial, tim.peters
Priority: normal Keywords:

Created on 2013-12-30 10:18 by niacdoial, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg207092 - (view) Author: Liam Marsh (niacdoial) Date: 2013-12-30 10:18
when does 3*0.1 make 0.30000000000000004 ?
YES it is the same program!
msg207094 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-12-30 11:42
This is how binary floating-point arithmetic works.  See

http://docs.python.org/3/tutorial/floatingpoint.html

for some explanations.
msg207096 - (view) Author: Liam Marsh (niacdoial) Date: 2013-12-30 12:41
can you add an approximation of the result in the command?
(ex: the biggest precision in the values is 0.1, so it won't show after 4.0)
meen while, thank you.
msg207120 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-12-31 15:42
> can you add an approximation of the result in the command?

I don't really understand what you're asking here.

If you're asking for the behaviour of multiplication to change so that it becomes more do-what-I-mean-ish, that's not going to happen.  You could try writing your own DWIM-style multiplication if that's what you want, but the basic multiplication operator should stay as it is now: a simple wrapper around the C multiplication, which on most machines has a simple, easily-stated and well-defined behaviour: return me the floating-point number that's closest to the exact mathematical result of the multiplication.
msg207122 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2013-12-31 16:01
@Liam, try using the "decimal" module instead.  That follows rules much like the ones people learn as kids.

>>> from decimal import Decimal as D
>>> D("0.1") * 3  # decimal results are computed exactly
Decimal('0.3')
>>> D("1.01") - D(".01")  # number of significant digits is preserved
Decimal('1.00')

Etc.
History
Date User Action Args
2022-04-11 14:57:56adminsetgithub: 64294
2013-12-31 16:01:28tim.peterssetnosy: + tim.peters
messages: + msg207122
2013-12-31 15:42:59mark.dickinsonsetmessages: + msg207120
2013-12-30 12:41:20niacdoialsetmessages: + msg207096
2013-12-30 11:43:28mark.dickinsonsetcomponents: + Interpreter Core, - Regular Expressions
2013-12-30 11:42:41mark.dickinsonsetstatus: open -> closed

nosy: + mark.dickinson
messages: + msg207094

resolution: not a bug
2013-12-30 10:18:22niacdoialcreate