fixedpoint cmp conundrum

Robert Brewer fumanchu at amor.org
Tue May 4 10:34:01 EDT 2004


[Tim Peters]
> > 4. Define an __eq__ method, which returns False if its arguments
> >    are non-comparable.

[Silly me]
> Looking at the SourceForge page, I think this is addressed by Bug
> #887290:
>
> 
>     def __eq__(self, other):
>         if isinstance(other, FixedPoint):
>             xn, yn, p = _norm(self, other, FixedPoint=type(self))
>             return not(cmp(xn, yn))
>         else:
>             return False
> 
>     def __ne__(self, other):
>         if isinstance(other, FixedPoint):
>             xn, yn, p = _norm(self, other, FixedPoint=type(self))
>             return cmp(xn, yn)
>         else:
>             return True

Duh. I should have said:

    def __eq__(self, other):
        if isinstance(other, FixedPoint):
            xn, yn, p = _norm(self, other, FixedPoint=type(self))
            return xn == yn
        else:
            return False

    def __ne__(self, other):
        if isinstance(other, FixedPoint):
            xn, yn, p = _norm(self, other, FixedPoint=type(self))
            return xn != yn
        else:
            return True

..using == and != instead of cmp(). I need to:

[] Stop working so late
[] Stop drinking so much Diet Coke
[] Stop putting so much rum in the Diet Coke
[] Go back to school ;)


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org

-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list