Updates:
Status: WontFix
Comment #3 on issue 2950 by smi...@gmail.com: Rational() doesn't work with
floats
http://code.google.com/p/sympy/issues/detail?id=2950
Here's an example:
repr(.2)
'0.20000000000000001'
.2.as_integer_ratio()
(3602879701896397L, 18014398509481984L)
If someone wanted a Rational from .2, they probably would want 2/10.
Rational could do this by using the str form of the float which is usually
what one expected. But there is no way for Rational to know whether someone
meant .20....1 or whether they wanted the simpler version.
Float falls into this trap, too, by allowing float as input. It may seem
that it is doing the right thing, but if you look at what really got stored
by Float(.2) you find that it stored the float data:
Float(.2)
0.200000000000000
_.n(22)
0.2000000000000000111022
Float partly avoids this issue by using only 15 digits of precision for the
number is stored which (I believe) is pretty generous since there are more
digits that can be stored in a float. The following appears to be accurate
to 18 digits:
Float(.1234567890121416182022).n(22)
0.1234567890121416183780
But what really got stored by Float(.2) was not an arbitrarily precise
value of .2, but the floating point approximation; not 2/10 but
.2.as_integer_ratio()
(3602879701896397L, 18014398509481984L)
It is able, btw, to store a more precise value by giving it a string (not a
float) and setting the precision to what one desires:
Float('.2',22).n(22)
0.2000000000000000000000
Float(.2,22).n(22) # garbage in, garbage out: a float isn't 22 digits
precise
0.2000000000000000111022
Rational, which creates an arbitrarily precise object, shouldn't have to
guess what the user really wanted; or put another way, the user should be
precise about what they want.
I'll mark this as WontFix as there was no other feedback.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.