Skip to content

Commit 09b51bd

Browse files
committed
Implement __floordiv__
1 parent 667bef4 commit 09b51bd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

cypari2/gen.pyx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ cdef class Gen(Gen_base):
537537
return new_gen(gmul(t0.g, t1.g))
538538

539539
def __div__(left, right):
540+
# Python 2 old-style division: same implementation as __truediv__
540541
cdef Gen t0, t1
541542
try:
542543
t0 = objtogen(left)
@@ -547,6 +548,15 @@ cdef class Gen(Gen_base):
547548
return new_gen(gdiv(t0.g, t1.g))
548549

549550
def __truediv__(left, right):
551+
"""
552+
Examples:
553+
554+
>>> from cypari2 import Pari; pari = Pari()
555+
>>> pari(11) / pari(4)
556+
11/4
557+
>>> pari("x^2 + 2*x + 3") / pari("x")
558+
(x^2 + 2*x + 3)/x
559+
"""
550560
cdef Gen t0, t1
551561
try:
552562
t0 = objtogen(left)
@@ -556,6 +566,25 @@ cdef class Gen(Gen_base):
556566
sig_on()
557567
return new_gen(gdiv(t0.g, t1.g))
558568

569+
def __floordiv__(left, right):
570+
"""
571+
Examples:
572+
573+
>>> from cypari2 import Pari; pari = Pari()
574+
>>> pari(11) // pari(4)
575+
2
576+
>>> pari("x^2 + 2*x + 3") // pari("x")
577+
x + 2
578+
"""
579+
cdef Gen t0, t1
580+
try:
581+
t0 = objtogen(left)
582+
t1 = objtogen(right)
583+
except Exception:
584+
return NotImplemented
585+
sig_on()
586+
return new_gen(gdivent(t0.g, t1.g))
587+
559588
def __mod__(left, right):
560589
"""
561590
Return ``left`` modulo ``right``.

0 commit comments

Comments
 (0)