| 9 | |
| 10 | |
| 11 | class PhysicalQuantity(float): |
| 12 | def __new__(cls, value): |
| 13 | return float.__new__(cls, value) |
| 14 | |
| 15 | def __add__(self, x): |
| 16 | assert_(isinstance(x, PhysicalQuantity)) |
| 17 | return PhysicalQuantity(float(x) + float(self)) |
| 18 | __radd__ = __add__ |
| 19 | |
| 20 | def __sub__(self, x): |
| 21 | assert_(isinstance(x, PhysicalQuantity)) |
| 22 | return PhysicalQuantity(float(self) - float(x)) |
| 23 | |
| 24 | def __rsub__(self, x): |
| 25 | assert_(isinstance(x, PhysicalQuantity)) |
| 26 | return PhysicalQuantity(float(x) - float(self)) |
| 27 | |
| 28 | def __mul__(self, x): |
| 29 | return PhysicalQuantity(float(x) * float(self)) |
| 30 | __rmul__ = __mul__ |
| 31 | |
| 32 | def __div__(self, x): |
| 33 | return PhysicalQuantity(float(self) / float(x)) |
| 34 | |
| 35 | def __rdiv__(self, x): |
| 36 | return PhysicalQuantity(float(x) / float(self)) |
| 37 | |
| 38 | |
| 39 | class PhysicalQuantity2(ndarray): |
no outgoing calls