2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-18 07:56:30 +08:00

units: support division by quantities in the same unit

This commit is contained in:
Sebastien Bourdeauducq 2014-08-16 10:27:44 +08:00
parent 7422a919cc
commit 232092166e

View File

@ -42,11 +42,19 @@ class Quantity:
return Quantity(other*self.amount, self.unit)
def __truediv__(self, other):
if isinstance(other, Quantity):
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):
if other.unit == self.unit:
return self.amount//other.amount
else:
return NotImplemented
else:
return Quantity(self.amount//other, self.unit)
def __neg__(self):