import unittest
from copy import copy
+def check_extsign(a, b):
+ if b.bits != 256:
+ return b
+ return SelectableInt(b.value, a.bits)
+
class SelectableInt:
def __init__(self, value, bits):
def __add__(self, b):
if isinstance(b, int):
b = SelectableInt(b, self.bits)
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value + b.value, self.bits)
def __sub__(self, b):
if isinstance(b, int):
b = SelectableInt(b, self.bits)
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value - b.value, self.bits)
def __mul__(self, b):
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value * b.value, self.bits)
def __div__(self, b):
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value / b.value, self.bits)
def __mod__(self, b):
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value % b.value, self.bits)
def __or__(self, b):
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value | b.value, self.bits)
def __and__(self, b):
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value & b.value, self.bits)
def __xor__(self, b):
+ b = check_extsign(self, b)
assert b.bits == self.bits
return SelectableInt(self.value ^ b.value, self.bits)
def __ge__(self, other):
if isinstance(other, SelectableInt):
+ other = check_extsign(self, other)
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
def __le__(self, other):
if isinstance(other, SelectableInt):
+ other = check_extsign(self, other)
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
def __gt__(self, other):
if isinstance(other, SelectableInt):
+ other = check_extsign(self, other)
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
def __lt__(self, other):
if isinstance(other, SelectableInt):
+ other = check_extsign(self, other)
assert other.bits == self.bits
other = other.value
if isinstance(other, int):
def __eq__(self, other):
if isinstance(other, SelectableInt):
+ other = check_extsign(self, other)
assert other.bits == self.bits
other = other.value
if isinstance(other, int):