Floating point multiplication in python
steve+comp.lang.python at pearwood.info
Tue Sep 6 09:11:10 CEST 2011
On Tue, 6 Sep 2011 03:57 pm xyz wrote:
> hi all:
> As we know , 1.1 * 1.1 is 1.21 .
> But in python ,I got following :
>>>> 1.1 * 1.1
The problem is that 1.1 is a *decimal* number, but computers use *binary*,
and it is impossible to express 1.1 exactly as a binary number. So when you
type 1.1 into nearly all computer languages, what you are actually getting
is a tiny bit more than 1.1:
which is the closest number to 1.1 that is possible using a C double
floating point number.
Normally you don't see it, because Python truncates the result when
but the difference is there.
More information about the Python-list