Skip to content

Commit

Permalink
style(Bits3val): show the number of bits in __repr__
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic30 committed Mar 23, 2024
1 parent a396e6d commit 9ee0fc9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pyMathBitPrecise/bits3t.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,13 @@ def _ternary(self, a, b):
return res

def __repr__(self):
if self.vld_mask != self._dtype.all_mask():
t = self._dtype
if self.vld_mask != t.all_mask():
m = ", mask {0:x}".format(self.vld_mask)
else:
m = ""
return "<{0:s} {1:s}{2:s}>".format(
self.__class__.__name__, repr(self.val), m)
typeDescrChar = 'b' if t.signed is None else 'i' if t.signed else 'u'
return f"<{self.__class__.__name__:s} {typeDescrChar:s}{t.bit_length():d} {repr(self.val):s}{m:s}>"


def bitsBitOp__val(self: Bits3val, other: Union[Bits3val, int],
Expand Down Expand Up @@ -689,7 +690,7 @@ def bitsCmp__val(self: Bits3val, other: Union[Bits3val, int],
ot = other._dtype
w = t.bit_length()
if t.signed != ot.signed or w != ot.bit_length():
raise TypeError(t, ot)
raise TypeError("Value compare supports only same width and sign type", t, ot)

vld = self.vld_mask & other.vld_mask
_vld = int(vld == t._all_mask)
Expand Down

0 comments on commit 9ee0fc9

Please sign in to comment.