Rajath, Thank you for these patches. Would you mind submitting your patches as pull requests on Github as opposed to email? It allows us to review and discuss the changes and will be included in automated testing on a variety of python installations. See https://github.com/sympy/sympy/wiki/Development-workflow for more info on how to do this. Let us know if you have any questions.
Jason moorepants.info +01 530-601-9791 On Tue, Feb 4, 2014 at 8:49 AM, Rajath Shashidhara < [email protected]> wrote: > I think consistency must be maintained in this case. > Rational(5.2) must be equal to Rational( '5.2' ) > > I made a patch for it. I've attached it to this mail. > Output after code changes: > > In [1]: from sympy import * > > In [2]: Rational('0.2') > Out[2]: 1/5 > > In [3]: Rational(0.2) > Out[3]: 1/5 > > > > > I ran the tests. Got this error message: > > _________________________________________________________________ sympy. > core.numbers.Rational_________________________________________________________________ > File "sympy/core/numbers.py", line 970, in sympy.core.numbers.Rational > Failed example: > Rational(.2) > Expected: > 3602879701896397/18014398509481984 > Got: > 1/5 > ============================================= tests finished: 2643 passed, > 1 failed, 3 skipped, in 178.48 seconds > ============================================= > > > > > *This error is expected. Every other test is passed. * > Since, mathematically, 0.2 != 3602879701896397/18014398509481984 > > Please give me your feedback on this. > > > > On Tuesday, February 4, 2014 1:26:56 PM UTC+5:30, F. B. wrote: >> >> >> >> On Tuesday, February 4, 2014 8:38:57 AM UTC+1, Rajath Shashidhara wrote: >>> >>> >>> >>> On Monday, February 3, 2014 11:05:50 PM UTC+5:30, mario wrote: >>>> >>>> 5.2 is a Python floating point number (a double) represented as >>>> 5854679515581645*2**(-50); >>>> using Rational( '5.2' ) it is recognized as exactly 52/10 >>>> >>>> >>> Isn't it better to have Rational(5.2) also store 26/5 , just like >>> Rational( '5.2' ) does ? >>> Is there a reason why it is left the way it is? >>> >>> >> It's Python that stores floating points that way. Moreover, the handling >> of the internal representation of 5.2 is handled by the CPU. It's the >> correct behavior as Python was not meant to be a CAS, just an ordinary >> programming language. >> >> I can make a patch for this, if more people feel this way. >>> >> >> You can? How? The only possibility I see is by modifying IPython to >> capture 5.2 before it gets evaluated by Python. Anyways, I don't see any >> reason for it, just use *Rational(26, 5)* >> > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.
