Pure Python rational numbers module for 2.5

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

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-18 07:54

    One more thing to try is Rat.py from demo folder in Python 2.5 maintenance branch. If i understand correctly, it is the daddy of 2.6 fractions. It's a single module without dependencies.

    >>> from Rat import rat
    >>> rat(1) / rat(3)
    Rat(1,3)
    >>> rat(1, 3) ** 2
    Rat(1,9)
    

    UPDATE: Nah, fractions.py is about 2.5 times faster for my task.

提交回复
热议问题