1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

sync up common math additions

This commit is contained in:
Joel Bender 2021-03-24 00:14:03 -04:00
parent 979a7e3653
commit ddc6a1ba71
2 changed files with 37 additions and 7 deletions

View File

@ -504,6 +504,35 @@ class Atomic(object):
"""Return True if arg is valid value for the class."""
raise NotImplementedError("call on a derived class of Atomic")
class CommonMath:
def __add__(self, other):
return self.value + other.value if isinstance(other, Atomic) else (self.value + other)
def __sub__(self, other):
return self.value - other.value if isinstance(other, Atomic) else (self.value - other)
def __mul__(self, other):
return self.value * other.value if isinstance(other, Atomic) else (self.value * other)
def __lt__(self, other):
return self.value < other.value if isinstance(other, Atomic) else (self.value < other)
def __gt__(self, other):
return self.value > other.value if isinstance(other, Atomic) else (self.value > other)
def __le__(self, other):
return self.value <= other.value if isinstance(other, Atomic) else (self.value <= other)
def __ge__(self, other):
return self.value >= other.value if isinstance(other, Atomic) else (self.value >= other)
def __ne__(self, other):
return self.value != other.value if isinstance(other, Atomic) else (self.value != other)
def __eq__(self, other):
return self.value == other.value if isinstance(other, Atomic) else (self.value == other)
#
# Null
#
@ -596,7 +625,7 @@ class Boolean(Atomic):
# Unsigned
#
class Unsigned(Atomic):
class Unsigned(Atomic, CommonMath):
_app_tag = Tag.unsignedAppTag
_low_limit = 0
@ -688,7 +717,7 @@ class Unsigned16(Unsigned):
# Integer
#
class Integer(Atomic):
class Integer(Atomic, CommonMath):
_app_tag = Tag.integerAppTag
@ -763,7 +792,7 @@ class Integer(Atomic):
# Real
#
class Real(Atomic):
class Real(Atomic, CommonMath):
_app_tag = Tag.realAppTag
@ -808,7 +837,7 @@ class Real(Atomic):
# Double
#
class Double(Atomic):
class Double(Atomic, CommonMath):
_app_tag = Tag.doubleAppTag

View File

@ -515,13 +515,13 @@ class CommonMath:
def __lt__(self, other):
return self.value < other.value if isinstance(other, Atomic) else (self.value < other)
def __gt__(self, other):
return self.value > other.value if isinstance(other, Atomic) else (self.value > other)
def __le__(self, other):
return self.value <= other.value if isinstance(other, Atomic) else (self.value <= other)
def __ge__(self, other):
return self.value >= other.value if isinstance(other, Atomic) else (self.value >= other)
@ -531,6 +531,7 @@ class CommonMath:
def __eq__(self, other):
return self.value == other.value if isinstance(other, Atomic) else (self.value == other)
#
# Null
#