@@ -3,6 +3,7 @@ from flint.utils.typecheck cimport typecheck
33from flint.types.fmpq cimport any_as_fmpq
44from flint.types.fmpz cimport any_as_fmpz
55from flint.types.fmpz cimport fmpz
6+ from flint.types.fmpz_mod cimport fmpz_mod
67from flint.types.fmpq cimport fmpq
78
89from flint.flintlib.flint cimport ulong
@@ -66,25 +67,28 @@ cdef class nmod(flint_scalar):
6667 def modulus (self ):
6768 return self .mod.n
6869
69- def __richcmp__ (s , t , int op ):
70- cdef mp_limb_t v
70+ def __richcmp__ (self , other , int op ):
7171 cdef bint res
72+
7273 if op != 2 and op != 3 :
7374 raise TypeError (" nmods cannot be ordered" )
74- if typecheck(s, nmod) and typecheck(t, nmod):
75- res = ((< nmod> s).val == (< nmod> t).val) and \
76- ((< nmod> s).mod.n == (< nmod> t).mod.n)
77- if op == 2 :
78- return res
79- else :
80- return not res
81- elif typecheck(s, nmod) and typecheck(t, int ):
82- res = s.val == (t % s.mod.n)
83- if op == 2 :
84- return res
85- else :
86- return not res
87- return NotImplemented
75+
76+ if typecheck(other, nmod):
77+ res = self .val == (< nmod> other).val and \
78+ self .mod.n == (< nmod> other).mod.n
79+ elif typecheck(other, int ):
80+ res = self .val == (other % self .mod.n)
81+ elif typecheck(other, fmpz):
82+ res = self .val == (int (other) % self .mod.n)
83+ elif typecheck(other, fmpz_mod):
84+ res = self .mod.n == (< fmpz_mod> other).ctx.modulus() and \
85+ self .val == int (other)
86+ else :
87+ return NotImplemented
88+
89+ if op == 2 :
90+ return res
91+ return not res
8892
8993 def __hash__ (self ):
9094 return hash ((int (self .val), self .modulus))
0 commit comments