Test divmod
============

>>> import gmpy2
>>> from gmpy2 import mpz, xmpz, mpq, mpfr, mpc
>>> from decimal import Decimal as D
>>> from fractions import Fraction as F
>>> from supportclasses import z
>>> a = mpz(123)
>>> b = mpz(456)
>>> c = 12345678901234567890

Test integer operations
-----------------------

>>> divmod(mpz(123),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpq(1,2),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpfr(1),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpc(1),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> ctx=gmpy2.context()
>>> ctx.divmod('a',456)
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(a,mpc(456))
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(mpc(1,2),mpc(3,4))
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(mpfr(2),mpfr(1))
(mpfr('2.0'), mpfr('0.0'))
>>> ctx.divmod(mpq(3,2),mpq(3,7))
(mpz(3), mpq(3,14))
>>> ctx.divmod(1,2,3)
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(456, 0)
Traceback (most recent call last):
  ...
ZeroDivisionError:
>>> ctx.divmod(a,b)
(mpz(0), mpz(123))
>>> ctx.divmod(123,456)
(mpz(0), mpz(123))
>>> divmod(mpz(1), mpc(1,2))
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpz(3), z)
(mpz(1), mpz(1))
>>> divmod(z, mpz(3))
(mpz(0), mpz(2))
>>> divmod(mpq(1,2), mpc(1,2))
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpfr(1), mpc(1,2))
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpc(1,2), mpc(1,2))
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpfr(1.2), mpfr(0.7))
(mpfr('1.0'), mpfr('0.5'))


>>> ctx=gmpy2.ieee(64)
>>> gmpy2.set_context(ctx)
>>> divmod(mpz(123),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpq(1,2),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpfr(1),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> divmod(mpc(1),'a')
Traceback (most recent call last):
  ...
TypeError:
>>> ctx=gmpy2.context()
>>> ctx.divmod('a',456)
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(a,mpc(456))
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(mpc(1,2),mpc(3,4))
Traceback (most recent call last):
  ...
TypeError:
>>> ctx.divmod(456, 0)
Traceback (most recent call last):
  ...
ZeroDivisionError:
>>> divmod(mpfr(1.2), mpfr(0.7))
(mpfr('1.0'), mpfr('0.5'))
>>> ctx.clear_flags()
>>> ctx.divzero
False
>>> divmod(mpfr(1.2), mpfr(0))
(mpfr('nan'), mpfr('nan'))
>>>
>>> gmpy2.set_context(gmpy2.context())
>>> with gmpy2.local_context(trap_divzero=True):
...     divmod(mpfr(1), mpfr(0))
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
gmpy2.DivisionByZeroError: divmod() division by zero
>>> with gmpy2.local_context(trap_invalid=True):
...     divmod(gmpy2.nan(), mpfr(1))
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
gmpy2.InvalidOperationError: divmod() invalid operation
>>> with gmpy2.local_context(trap_invalid=True):
...     divmod(mpfr(1), gmpy2.inf())
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
gmpy2.InvalidOperationError: divmod() invalid operation
