Pure Python rational numbers module for 2.5

前端 未结 3 863
既然无缘
既然无缘 2021-01-18 07:09

Has anybody seen such a thing? Small self-sufficient modules are preferred.

3条回答
  •  遇见更好的自我
    2021-01-18 08:07

    SymPy is a symbolic maths library written entirely in Python and has full support for rational numbers. From the tutorial:

    >>> from sympy import *
    >>> a = Rational(1,2)
    
    >>> a
    1/2
    
    >>> a*2
    1
    
    >>> Rational(2)**50/Rational(10)**50
    1/88817841970012523233890533447265625
    

    There is also GMP for Python (GMPY) which, while not pure Python, is probably more efficient.

提交回复
热议问题