gmpy2 qdiv() returns mpq where mpz would be possible

83 views Asked by At

I wonder if I don't get something here... Why does qdiv(8,2) return an mpq instead of an mpz?

See here:

Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gmpy2 import qdiv
>>> help(qdiv)
Help on built-in function qdiv in module gmpy2:

qdiv(...)
    qdiv(x[, y=1]) -> number

    Return x/y as 'mpz' if possible, or as 'mpq' if x is not exactly
    divisible by y.
>>> qdiv(8,2)
mpq(4,1)
>>> qdiv(4,1)
mpz(4)

I thought the whole idea was to return an mpz if possible?

1

There are 1 answers

2
casevh On

I believe that is a bug that was fixed in version 2.0.5. Your example works with 2.0.8. What version of gmpy2 are you using?

Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gmpy2
>>> gmpy2.qdiv(8,2)
mpz(4)
>>> gmpy2.qdiv(4,1)
mpz(4)
>>> gmpy2.version()
'2.0.8'
>>> 

Edit

This is a bug in gmpy2 2.1.0 alpha release. A fix has been committed to the master trunk at the main repository - gmpy2. It will be included in version 2.1.0a5.