On Sat, Dec 1, 2012 at 12:17 PM, Ronan Lamy <ronan.l...@gmail.com> wrote:
> Le 30/11/2012 22:23, Aaron Meurer a écrit : > >> 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. >> > > There are two things that bite us again and again: constructors that do > too much and polymorphic functions resulting from the conglomeration of > several simple functions under the same name. Here, both apply. > > So I suggest a more radical change to the constructor: it should only > accept the two-argument form, and "rat = Rational(p, q)" should have the > following post-conditions: > > assert isinstance(rat, Rational) > assert rat.p == p > assert rat.q == q > > After working with this for some time now, I totally agree. I'm not sure where this all should go. My hunch is in Number. Objects themselves have methods for getting out the underlying simple data, e.g. Decimal.as_tuple(); float.as_integer_ratio(); mpf.man_exp, and if someone is using them they should unpack the object so the receiving function doesn't have to be a polyglot. -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.