bendudson / py4cl

Call python from Common Lisp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Conversion of ratios to Python 2

tanders opened this issue · comments

Firstly, thanks for py4cl.

I noticed some problem in the transformation of Lisp ratios in Python 2. Currently, py4cl does the following.

 (py4cl::pythonize 1/4)
=> "1/4"

This behaviour is wrong in Python 2, because there 1/4 evaluates to 0 (in python 2.7, the / operator performs integer division).

There are several ways around, of course, including to import in Python 2.7 the following.

from __future__ import division

Another would be to change the behaviour of pythonize to ensure that the result is a float, e.g.,

 (py4cl::pythonize 1/4)
=> "1/4.0"

However, ideally I would like to have the following translation, after the Python fractions module was imported.

 (py4cl::pythonize 1/4)
=> "Fraction(1, 4)"

Thanks for the suggestion! I've added the fractions.Fraction solution to PR #27