Search code examples
pythonmpmathgmpy

How do I know if mpmath is using gmpy or gmpy2?


I know of

import mpmath as mp
print mp.libmp.BACKEND

but if I'm not mistaken it won't say if I'm using gmpy or gmpy2.

Also, I that every time you use a newer version of something you don't get the version number next to it but since I can import gmpy and gmpy2 separately I'm a bit worried I may be using the older version of gmpy.

Thank you

UPDATE:

I also tried the following which confused / worried me.

import mpmath as mp
import gmpy as gm
import gmpy2 as gm2
print mp.mpf('1') == gm.mpf('1')
# Result is FALSE
print mp.mpf('1') == gm2.mpfr('1')
# Result is FALSE
print gm.mpf('1') == gm2.mpfr('1')
# Result is FALSE
print mp.mpf('1') == 1
# Result is TRUE
print gm.mpf('1') == 1
# Result is TRUE
print gm2.mpfr('1') == 1
# Result is TRUE

What the heck?


Solution

  • mpmath will try to import gmpy2 first.

    While you can import both gmpy and gmpy2 at the same time, it is not a supported scenario since gmpy and gmpy2 aren't aware of each other.

    I maintain both gmpy and and gmpy2 but I consider gmpy to be obsolete and gmpy2 should be used instead.