Closed shortjonescipher closed 6 years ago
Thanks, I fixed it and added test case to Travis CI.
(BTW, I couldn't reproduce this behavior... (Ubuntu 16.04.1 w/ Python 2.7.14, gmpy 1.17, gmpy2 2.0.8))
> python
Python 2.7.14 (default, Jan 27 2018, 18:58:58)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmpy, gmpy2
>>> gmpy.invert(2713, 1)
mpz(0)
>>> gmpy2.invert(2713, 1)
mpz(0)
>>>
Sometimes mpqs() calls modinv(a, m) with modulus m=1, which is bound to fail. It causes a zero division exception. Here is an example with print('modinv', a, m) inserted in _modinv_gmpy(a, m). I don't know the mpqs algorithm well enough to understand why this happens.