@@ -3,6 +3,7 @@ from flint.utils.typecheck cimport typecheck
3
3
from flint.types.fmpq cimport any_as_fmpq
4
4
from flint.types.fmpz cimport any_as_fmpz
5
5
from flint.types.fmpz cimport fmpz
6
+ from flint.types.fmpz_mod cimport fmpz_mod
6
7
from flint.types.fmpq cimport fmpq
7
8
8
9
from flint.flintlib.flint cimport ulong
@@ -66,25 +67,29 @@ cdef class nmod(flint_scalar):
66
67
def modulus (self ):
67
68
return self .mod.n
68
69
69
- def __richcmp__ (s , t , int op ):
70
- cdef mp_limb_t v
70
+ def __richcmp__ (self , other , int op ):
71
71
cdef bint res
72
+
72
73
if op != 2 and op != 3 :
73
74
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
+ else :
92
+ return not res
88
93
89
94
def __hash__ (self ):
90
95
return hash ((int (self .val), self .modulus))
0 commit comments