Skip to content
Snippets Groups Projects
Commit 7ce5172f authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

add binary shift operations to `AtomicNumber`

parent 0e595356
No related branches found
No related tags found
No related merge requests found
# v2.9.7
* add binary shift operations to `AtomicNumber`
__version__ = '2.9.7_a1'
__version__ = '2.9.7_a2'
......@@ -99,6 +99,32 @@ class AtomicNumber(Monitor):
def __gt__(self, other: Number):
return self.value > other
@Monitor.synchronized
def __lshift__(self, other: int) -> Number:
return self.value << other
@Monitor.synchronized
def __rshift__(self, other: int) -> Number:
return self.value >> other
@Monitor.synchronized
def __rlshift__(self, other: int) -> Number:
return other << self.value
@Monitor.synchronized
def __rrshift__(self, other: int) -> Number:
return other >> self.value
@Monitor.synchronized
def __ilshift__(self, other: int) -> 'AtomicNumber':
self.value <<= other
return self
@Monitor.synchronized
def __irshift__(self, other: int) -> 'AtomicNumber':
self.value >>= other
return self
@Monitor.synchronized
def __ge__(self, other: Number):
return self.value >= other
......
......@@ -45,6 +45,11 @@ class TestConcurrent(unittest.TestCase):
self.assertIsInstance(a, AtomicNumber)
self.assertEqual(a, 3)
self.assertEqual(a << 1, 0b110)
self.assertEqual(a >> 1, 1)
self.assertEqual(1 << a, 0b1000)
self.assertEqual(0b111000 >> a, 0b111)
self.assertEqual(a >> 1, 1)
self.assertIsInstance(a + 2, int)
self.assertEqual(a | 4, 7)
self.assertEqual(a & 2, 2)
......@@ -73,6 +78,10 @@ class TestConcurrent(unittest.TestCase):
self.assertEqual(a, 3)
a ^= 0
self.assertEqual(a, 3)
a <<= 1
self.assertEqual(a, 0b110)
a >>= 1
self.assertEqual(a, 3)
a /= 1
self.assertEqual(a, 3.0)
a //= 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment