Conversion of ratios to Python 2
tanders opened this issue · comments
Torsten Anders commented
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)"
Ben Dudson commented
Thanks for the suggestion! I've added the fractions.Fraction
solution to PR #27