Issue 20095: what is that result!? (original) (raw)

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:56 admin set github: 64294
2013-12-31 16:01:28 tim.peters set nosy: + tim.petersmessages: +
2013-12-31 15:42:59 mark.dickinson set messages: +
2013-12-30 12:41:20 niacdoial set messages: +
2013-12-30 11:43:28 mark.dickinson set components: + Interpreter Core, - Regular Expressions
2013-12-30 11:42:41 mark.dickinson set status: open -> closednosy: + mark.dickinsonmessages: + resolution: not a bug
2013-12-30 10🔞22 niacdoial create