Skip to content

Commit

Permalink
Trac #23060: py3: get rid of cmp in complex interval field
Browse files Browse the repository at this point in the history
a tiny ticket, on our long way to python3

URL: https://trac.sagemath.org/23060
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): John Palmieri
  • Loading branch information
Release Manager authored and vbraun committed May 27, 2017
2 parents fefbe44 + d67aef5 commit 07776c7
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/sage/rings/complex_interval_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ class ComplexIntervalField_class(ring.Field):
We can load and save complex numbers and the complex interval field::
sage: cmp(loads(z.dumps()), z)
0
sage: saved_z = loads(z.dumps())
sage: saved_z.endpoints() == z.endpoints()
True
sage: loads(CIF.dumps()) == CIF
True
sage: k = ComplexIntervalField(100)
Expand Down Expand Up @@ -375,25 +376,41 @@ def _middle_field(self):
self.__middle_field = complex_field.ComplexField(self._prec)
return self.__middle_field

def __cmp__(self, other):
def __eq__(self, other):
"""
Compare ``other`` to ``self``.
Test whether ``self`` is equal to ``other``.
If ``other`` is not a :class:`ComplexIntervalField_class`, compare by
type, otherwise compare by precision.
If ``other`` is not a :class:`ComplexIntervalField_class`,
return ``False``. Otherwise, return ``True`` if ``self`` and
``other`` have the same precision.
EXAMPLES::
sage: cmp(CIF, ComplexIntervalField(200))
-1
sage: cmp(CIF, CC) != 0
sage: CIF == ComplexIntervalField(200)
False
sage: CIF == CC
False
sage: CIF == CIF
True
sage: cmp(CIF, CIF)
0
"""
if not isinstance(other, ComplexIntervalField_class):
return cmp(type(self), type(other))
return cmp(self._prec, other._prec)
return False
return self._prec == other._prec

def __ne__(self, other):
"""
Test whether ``self`` is not equal to ``other``.
EXAMPLES::
sage: CIF != ComplexIntervalField(200)
True
sage: CIF != CC
True
sage: CIF != CIF
False
"""
return not (self == other)

def __call__(self, x, im=None):
"""
Expand Down

0 comments on commit 07776c7

Please sign in to comment.