From 52bf04dd94216f95d0ac1838c13e24827ef89353 Mon Sep 17 00:00:00 2001 From: Christian Caremoli <> Date: Mon, 19 Nov 2007 10:19:24 +0000 Subject: [PATCH] =?utf8?q?CCAR:=20ajout=20=5F=5Fhash=5F=5F=20et=20utilisat?= =?utf8?q?ion=20division=20sp=C3=A9ciale=20pour=20entiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Extensions/param2.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Extensions/param2.py b/Extensions/param2.py index 765dd1e0..e91e3e1b 100644 --- a/Extensions/param2.py +++ b/Extensions/param2.py @@ -53,13 +53,23 @@ class Formula: def __le__( self, other ): return self.eval() <= other def __gt__( self, other ): return self.eval() > other def __ge__( self, other ): return self.eval() >= other + def __hash__(self):return id(self) + +def _div(a,b): + if isinstance(a,(int,long)) and isinstance(b,(int,long)): + if a%b: + return a/b + else: + return a//b + else: + return a/b class Binop(Formula): opmap = { '+': lambda a, b: a + b, '*': lambda a, b: a * b, '-': lambda a, b: a - b, - '/': lambda a, b: a / b, + '/': _div, '//': lambda a, b: a // b, '**': lambda a, b: a ** b, '[]': lambda a, b: a[b] , -- 2.39.2