Macaulay2 » Documentation
Packages » Python » PythonObject » quotientRemainder(PythonObject,PythonObject)
next | previous | forward | backward | up | index | toc

quotientRemainder(PythonObject,PythonObject) -- get the quotient and remainder when dividing Python objects

Description

This returns a sequence containing both the quotient and remainder when dividing the first argument by the second. Note that the return value is a Macaulay2 sequence and not a Python tuple. This makes it useful with parallel assignment.

i1 : (q, r) = quotientRemainder(toPython 5, toPython 3)

o1 = (1, 2)

o1 : Sequence
i2 : q

o2 = 1

o2 : PythonObject of class int
i3 : r

o3 = 2

o3 : PythonObject of class int

If one of the arguments is a Macaulay2 object, then it is first converted to a Python object before dividing.

i4 : quotientRemainder(toPython 9, 5)

o4 = (1, 4)

o4 : Sequence
i5 : quotientRemainder(11, toPython 7)

o5 = (1, 4)

o5 : Sequence

Note that the behavior of this function for integers differs between Macaulay2 and Python. In particular, in Macaulay2, the quotient is rounded down when y is positive and up when it is negative, and the remainder is always nonnegative. In Python, the quotient is always rounded down and the remainder will have the same sign as y.

i6 : quotientRemainder(5, -3)

o6 = (-1, 2)

o6 : Sequence
i7 : quotientRemainder(toPython 5, -3)

o7 = (-2, -1)

o7 : Sequence

See also

Ways to use this method:


The source of this document is in Python/doc/arithmetic.m2:731:0.