forked from M-Labs/artiq
units: support division by quantities in the same unit
This commit is contained in:
parent
7422a919cc
commit
232092166e
|
@ -42,12 +42,20 @@ class Quantity:
|
||||||
return Quantity(other*self.amount, self.unit)
|
return Quantity(other*self.amount, self.unit)
|
||||||
def __truediv__(self, other):
|
def __truediv__(self, other):
|
||||||
if isinstance(other, Quantity):
|
if isinstance(other, Quantity):
|
||||||
return NotImplemented
|
if other.unit == self.unit:
|
||||||
return Quantity(self.amount/other, self.unit)
|
return self.amount/other.amount
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
else:
|
||||||
|
return Quantity(self.amount/other, self.unit)
|
||||||
def __floordiv__(self, other):
|
def __floordiv__(self, other):
|
||||||
if isinstance(other, Quantity):
|
if isinstance(other, Quantity):
|
||||||
return NotImplemented
|
if other.unit == self.unit:
|
||||||
return Quantity(self.amount//other, self.unit)
|
return self.amount//other.amount
|
||||||
|
else:
|
||||||
|
return NotImplemented
|
||||||
|
else:
|
||||||
|
return Quantity(self.amount//other, self.unit)
|
||||||
|
|
||||||
def __neg__(self):
|
def __neg__(self):
|
||||||
return Quantity(-self.amount, self.unit)
|
return Quantity(-self.amount, self.unit)
|
||||||
|
|
Loading…
Reference in New Issue