On Thu, Feb 08, 2007 at 01:22:46AM -0500, didier deshommes wrote:
>
> On 2/8/07, Luis Finotti <[EMAIL PROTECTED]> wrote:
> > Thanks! I could not find that in the Reference Manual...
> >
> > On the other hand, it seems that Sage (or Python) does not handle
> > equality of reals very well:
>
> Hi,
> this is most likey due to rounding errors. The equality holds for fractions:
>
> {{{
> sage: 1/2==1/2
> True
> sage: 1/2==1/2+1-1
> True
> }}}
>
> But note that rearranging your equation, we can still get equality:
> {{{
> sage: sqrt (2) - sqrt(2) + 1 - 1 ==0
> True
> }}}
In my experience, rearranging sometimes works and sometimes doesn't (speaking
from general C++ experience). Basically, the moral of the story is that testing
equality of floating point numbers is simply a bad idea in any system. My
belief is that the Real field should simply not have an == operator defined
because it's misleading. I think it should be replaced with a function
"CloseEnough" (or something like that) that takes an epsilon determining
precisely how close is "CloseEnough".
--
Joel
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---