On Wed, 12 Sep 2012 at 10:14PM +0800, P Purkayastha wrote:
> Can anyone point out what is wrong with this comparison:
> 
> sage: 0.2 + 0.1 == 0.3
> False
> 
> It seems baffling that something as simple as this returns False.

Off the top of my head, I'd say it's because comparing floating-point
numbers is tricky. As I understand, none of those numbers can be
expressed exactly as a float, so internally Python/Sage/whatever is
using an approximation -- and after the addition, the error is big
enough to return False.


Dan

--
---  Dan Drake
-----  http://math.pugetsound.edu/~ddrake
-------

Attachment: signature.asc
Description: Digital signature

Reply via email to