Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Fix comparison for MPComplexField
Browse files Browse the repository at this point in the history
  • Loading branch information
jdemeyer committed May 9, 2015
1 parent 6a3cb27 commit c448299
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/sage/rings/complex_mpc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import re
import real_mpfr
import weakref

from sage.structure.parent import Parent
from sage.structure.parent_gens import ParentWithGens
from sage.structure.parent cimport Parent
from sage.structure.parent_gens cimport ParentWithGens
from sage.structure.element cimport RingElement, Element, ModuleElement
from sage.categories.map cimport Map

Expand Down Expand Up @@ -459,7 +459,7 @@ cdef class MPComplexField_class(sage.rings.ring.Field):
if isinstance(S, MPComplexField_class) and S.prec() >= self.__prec:
#FIXME: What map when rounding modes differ but prec is the same ?
# How to provide commutativity of morphisms ?
# Change __cmp__ when done
# Change _cmp_ when done
return MPCtoMPC(S, self)

if isinstance(S, ComplexField_class) and S.prec() >= self.__prec:
Expand All @@ -483,9 +483,12 @@ cdef class MPComplexField_class(sage.rings.ring.Field):
"""
return __create__MPComplexField_version0, (self.__prec, self.__rnd_str)

def __cmp__(self, other):
def __richcmp__(left, right, int op):
return (<Parent>left)._richcmp(right, op)

cpdef int _cmp_(self, right) except -2:
"""
Compare ``self`` and ``other``.
Compare ``self`` and ``other``, ignoring the rounding mode.
EXAMPLES::
Expand All @@ -496,16 +499,12 @@ cdef class MPComplexField_class(sage.rings.ring.Field):
sage: MPComplexField(10,rnd='RNDZN') == MPComplexField(10,rnd='RNDZU')
True
"""
if not isinstance(other, MPComplexField_class):
return -1
cdef MPComplexField_class _other
_other = other # to access C structure
#FIXME: if we choose a priority between rounding modes in
#order to provide commutativity of morphisms then rounding
#mode will matter
if self.__prec == _other.__prec: # and self.__rnd == _other.__rnd:
return 0
return 1
cdef int c = cmp(type(self), type(right))
if c:
return c

cdef MPComplexField_class other = <MPComplexField_class>right
return cmp(self.__prec, other.__prec)

def gen(self, n=0):
"""
Expand Down Expand Up @@ -1169,7 +1168,14 @@ cdef class MPComplexNumber(sage.structure.element.FieldElement):
rnd = (<MPComplexField_class>self._parent).__rnd
return complex(mpfr_get_d(self.value.re, rnd_re(rnd)), mpfr_get_d(self.value.im, rnd_im(rnd)))

def __cmp__(self, other):
# Boilerplate comparison code
def __richcmp__(left, right, int op):
return (<Element>left)._richcmp(right, op)

def __cmp__(left, right):
return (<Element>left)._cmp(right)

cpdef int _cmp_(self, Element other) except -2:
r"""
Compare ``self`` to ``other``.
Expand Down

0 comments on commit c448299

Please sign in to comment.