I understand that the number 0.3 cannot be exactly represented in binary, and thats why doing something like:
0.1+0.2==0.3
gives False
as an answer.
However even if the number cannot be exactly represented, the result should still be True. Here's my reasoning:
Python will do the operation 0.1+0.2 and the result will not be exactly 0.3, it will be some number close to 0.3 that will be stored as the left operand of the comparison.
But then it has to take the right operand 0.3
, convert it to a number, which will give again number not exactly equal to 0.3 and store it as the right operand of the comparison.
Finally compare both numbers.
So the result should actually give True, even if internally it will be comparing two numbers and none of them will actually be 0.3
What am I missing here? If the number cannot be exactly represented, then this must be true for both operands, so we will be comparing something like
0.1+0.2==0.3
0.30000000000000004 == 0.30000000000000004
True