It's worth pointing out that Float does the same thing, if you give it a high enough precision. Try Float(3.2, 100) for example.
To me, it should just work. Yes, we should encourage the use of strings over float literals, but Rational(float) not working makes it seem as if the conversion is not supported, which is not true at all. Aaron Meurer On Nov 30, 2012, at 1:32 PM, smichr <[email protected]> wrote: At http://code.google.com/p/sympy/issues/detail?can=2&q=2950 I give the reasons why I don't think it should. The work is at https://github.com/sympy/sympy/pull/1680 (which disallows it). Should we just let the user shoot themselves in the foot if they request Rational from floats or should we insist that input be integer or string? Note: I incorrectly stated on the PR that Decimal requires int or str input. It is "unprejudiced" in accepting floats as well (as demonstrated in the python docs). >>> Decimal(3.2) Decimal('3.20000000000000017763568394002504646778106689453125') But here is the problem: >>> (3.2).as_integer_ratio() (3602879701896397L, 1125899906842624L) >>> Rational(*_) 3602879701896397/1125899906842624 Many would expect Rational(3.2) to give 16/5 but that's not the ratio that is represented by float 3.2. In order to get that one would have to limit the denominator: >>> _.limit_denominator(10**15) 3199999999999997/999999999999999 >>> _.limit_denominator(10**14) 16/5 Alternatively, internally, the float could be converted to a string (which gives abaout 12 digits of precision) so Rational(3.2) would actually do >>> Rational(str(3.2)) 16/5 Thanks for any comments, Chris -- You received this message because you are subscribed to the Google Groups "sympy" group. To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/Ap9WvE14VdoJ. 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?hl=en. -- You received this message because you are subscribed to the Google Groups "sympy" 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?hl=en.
