Comment #4 on issue 2950 by [email protected]: Rational() doesn't work
with floats
http://code.google.com/p/sympy/issues/detail?id=2950
I agree with what you said. There is also a good explanation of the problem
in the official Python tutorial[1]. To be honest, I wasn't aware of the
problem with different bases when I opened this bug report. Now I know
better, but I still do have some gripes though.
The problem in SymPy is currently that Rational does a thing even worse
than guess when you give it a floating point number - it changes the number
(to int) and returns a rational representation of the changed number. A
concrete example:
In [85]: Rational(3.2)
Out[85]: 3
Why would anyone want that? I think that it should either raise a TypeError
or return a rational number just like the float.as_integer_ratio() does.
The latter will mostly not be what user expected because most base-10
decimal numbers can't be exactly represented in base-2, but it is better
than what Rational does at the moment. The raising of TypeError actually
seems like the best solution to me. In the error we can explain the problem
and point user to [1] and tell him that he should paste floats as strings
for the exact result or use nsimplify to get an approximation.
[1] http://docs.python.org/tutorial/floatingpoint.html
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.