fuzzylogician / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Modular inverse wrong for 0. #72

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. import gmpy
2. gmpy.invert(0,5)
3. >  mpz(0)

What is the expected output? What do you see instead?

> Modular inverse of 0 should give an error.

What version of the product are you using? On what operating system?
gmpy 1.16 with python 3.3.0

Please provide any additional information below.

Original issue reported on code.google.com by temp.us...@gmail.com on 20 Apr 2013 at 7:27

GoogleCodeExporter commented 8 years ago
Tried gmpy2, same.

Original comment by temp.us...@gmail.com on 20 Apr 2013 at 7:29

GoogleCodeExporter commented 8 years ago
I verified the behavior of GMP's mpz_invert() and it is documented to return 0. 
gmpy and gmpy2 just reflect the same behavior.

gmpy.divm(a, b, m) provides a more general solution to a=bx (mod m) and divm() 
does raise an exception if b is 0.

I need to think about the implications of changing the behavior of invert(). It 
has had the current behavior for many years.

In any case, the SO answer should edited to use divm().

Thanks for opening the issue.

Original comment by casevh on 20 Apr 2013 at 7:55

GoogleCodeExporter commented 8 years ago
I changed the behavior in GMPY2 2.0.1 to raise an exception. I won't be making 
any change to GMPY 1.x.

Original comment by casevh on 28 Jul 2013 at 5:03