On Wed, Sep 12, 2012 at 8:11 AM, Jori Mantysalo <[email protected]> wrote:
> On Wed, 12 Sep 2012, Dan Drake wrote:
>
>>> sage: 0.2 + 0.1 == 0.3
>>> False
>
>
>> using an approximation -- and after the addition, the error is big
>> enough to return False.
...


Incidentally, the Python Decimal module was designed to address this issue:

  http://docs.python.org/library/decimal.html

For example,

sage: from decimal import Decimal as RealNumber
sage: 0.2 + 0.1 == 0.3
True

Arithmetic will be slower and many special functions won't work at
all.   But if you're just doing basic arithmetic with decimal numbers,
it will have exactly the semantics you expect.

sage: sin(0.2)
...
TypeError: cannot coerce arguments: no canonical coercion from <class
'decimal.Decimal'> to Symbolic Ring

That this sort of thing doesn't work could actually be fixed if
somebody wanted to...

William

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to