Skip to content

Commit a068011

Browse files
committed
Fix fmpz_mod_poly.leading_coefficient() under PyPy
1 parent ad97112 commit a068011

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/flint/types/fmpz_mod_poly.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,9 @@ cdef class fmpz_mod_poly(flint_poly):
880880
"""
881881
return self[0]
882882

883+
# XXX: Methods like leading_coefficient() that are generic should be moved
884+
# to the flint_poly base class rather than defined here.
885+
883886
def leading_coefficient(self):
884887
"""
885888
Return the leading coefficient of this polynomial.
@@ -889,6 +892,12 @@ cdef class fmpz_mod_poly(flint_poly):
889892
>>> f.leading_coefficient()
890893
fmpz_mod(3, 163)
891894
"""
895+
# XXX: This is a workaround for a Cython/PyPy bug:
896+
# https://github.com/flintlib/python-flint/issues/74
897+
# https://github.com/cython/cython/issues/5776
898+
d = self.degree()
899+
if d < 0:
900+
return self.ctx.mod.zero()
892901
return self[self.degree()]
893902

894903
def reverse(self, degree=None):

0 commit comments

Comments
 (0)