Skip to content

Commit

Permalink
Fix fmpz_mod_poly.leading_coefficient() under PyPy
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarbenjamin committed Oct 21, 2023
1 parent ad97112 commit a068011
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/flint/types/fmpz_mod_poly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@ cdef class fmpz_mod_poly(flint_poly):
"""
return self[0]

# XXX: Methods like leading_coefficient() that are generic should be moved
# to the flint_poly base class rather than defined here.

def leading_coefficient(self):
"""
Return the leading coefficient of this polynomial.
Expand All @@ -889,6 +892,12 @@ cdef class fmpz_mod_poly(flint_poly):
>>> f.leading_coefficient()
fmpz_mod(3, 163)
"""
# XXX: This is a workaround for a Cython/PyPy bug:
# https://github.com/flintlib/python-flint/issues/74
# https://github.com/cython/cython/issues/5776
d = self.degree()
if d < 0:
return self.ctx.mod.zero()
return self[self.degree()]

def reverse(self, degree=None):
Expand Down

0 comments on commit a068011

Please sign in to comment.