details: http://hg.sympy.org/sympy/rev/23691e3ea6aa changeset: 1832:23691e3ea6aa user: Fabian Seoane <[EMAIL PROTECTED]> date: Wed Oct 22 16:15:39 2008 +0200 description: Make Rational accept arguments of type Integer. --- sympy/core/numbers.py | 12 +++++++++--- sympy/core/tests/test_numbers.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-)
diffs (59 lines): diff -r 876257540928 -r 23691e3ea6aa sympy/core/numbers.py --- a/sympy/core/numbers.py Mon Oct 20 16:48:16 2008 +0200 +++ b/sympy/core/numbers.py Wed Oct 22 16:15:39 2008 +0200 @@ -487,7 +487,7 @@ is_Rational = True - @Memoizer(type, (int, long, str), MemoizerArg((int, long, type(None)), name="q")) + @Memoizer(type, (int, long, str, 'Integer'), MemoizerArg((int, long, 'Integer', type(None)), name="q")) def __new__(cls, p, q = None): if q is None: if isinstance(p, str): @@ -512,8 +512,8 @@ if q==1: return Integer(p) if p==1 and q==2: return S.Half obj = Basic.__new__(cls) - obj.p = p - obj.q = q + obj.p = int(p) + obj.q = int(q) #obj._args = (p, q) return obj @@ -788,6 +788,12 @@ return self else: return Integer(-self.p) + + def __mod__(self, other): + return self.p % other + + def __rmod__(self, other): + return other % self.p # TODO make it decorator + bytecodehacks? def __add__(a, b): diff -r 876257540928 -r 23691e3ea6aa sympy/core/tests/test_numbers.py --- a/sympy/core/tests/test_numbers.py Mon Oct 20 16:48:16 2008 +0200 +++ b/sympy/core/tests/test_numbers.py Wed Oct 22 16:15:39 2008 +0200 @@ -40,6 +40,19 @@ assert igcdex(2, 3) == (-1, 1, 1) assert igcdex(10, 12) == (-1, 1, 2) assert igcdex(100, 2004) == (-20, 1, 4) + +def test_Rational_new(): + """" + Test for Rational constructor + """ + n1 = Rational(1,2) + assert n1 == Rational(Integer(1), 2) + assert n1 == Rational(Integer(1), Integer(2)) + assert n1 == Rational(1, Integer(2)) + + raises(ValueError, 'Rational(1.2)') + raises(ValueError, "Rational(Symbol('x'))") + raises(ValueError, 'Rational(Rational(1,2))') def test_Rational_cmp(): n1 = Rational(1,4) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy-commits" group. To post to this group, send email to sympy-commits@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy-commits?hl=en -~----------~----~----~----~------~----~------~--~---