osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about floating point


Hi all

I know about this gotcha -

>>> x = 1.1 + 2.2
>>> x
3.3000000000000003

According to the docs, the reason is that "numbers like 1.1 and 2.2 do not 
have exact representations in binary floating point."

So when I do this -

>>> y = 3.3
>>> y
3.3

what exactly is happening? What is 'y' at this point?

Or if I do this -

>>> z = (1.1 + 2.2) * 10 / 10
>>> z
3.3

What makes it different from the first example?

Thanks

Frank Millman