From 232092166eae4122faa398b63a99ff2cfc7fdd7e Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 16 Aug 2014 10:27:44 +0800 Subject: [PATCH] units: support division by quantities in the same unit --- artiq/language/units.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/artiq/language/units.py b/artiq/language/units.py index ad84974da..d12c3e95b 100644 --- a/artiq/language/units.py +++ b/artiq/language/units.py @@ -42,12 +42,20 @@ class Quantity: return Quantity(other*self.amount, self.unit) def __truediv__(self, other): if isinstance(other, Quantity): - return NotImplemented - return Quantity(self.amount/other, self.unit) + if other.unit == self.unit: + return self.amount/other.amount + else: + return NotImplemented + else: + return Quantity(self.amount/other, self.unit) def __floordiv__(self, other): if isinstance(other, Quantity): - return NotImplemented - return Quantity(self.amount//other, self.unit) + if other.unit == self.unit: + return self.amount//other.amount + else: + return NotImplemented + else: + return Quantity(self.amount//other, self.unit) def __neg__(self): return Quantity(-self.amount, self.unit)