The gmpy2 mpz type supports arbitrary precision integers. It should be a drop-in replacement for Python’s long type. Depending on the platform and the specific operation, an mpz will be faster than Python’s long once the precision exceeds 20 to 50 digits.
SymPy is a pure Python library, however to improve the speed of computations it can take advantage of gmpy library to speedup coefficient arithmetics (also known as ground domain arithmetics). Ground types are set automatically, so if gmpy is not available, it simply won’t be used.
在使用gmpy2或者sympy相关函数的后,返回值可能会是mpz类型,而非int。用int()转换即可。
例如libnum.n2s函数无法处理mpz类型,int转换即可,否则会报len_in_bits defined only for ints