File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ def __ge__(self, other):
263263
264264 def __abs__ (self ):
265265 if self .shape ().signed :
266- return Mux (self >= 0 , self , - self )
266+ return Mux (self >= 0 , self , - self )[: len ( self )]
267267 else :
268268 return self
269269
Original file line number Diff line number Diff line change @@ -675,6 +675,17 @@ def test_hash(self):
675675 with self .assertRaises (TypeError ):
676676 hash (Const (0 ) + Const (0 ))
677677
678+ def test_abs (self ):
679+ s = Signal (4 )
680+ self .assertRepr (abs (s ), """
681+ (sig s)
682+ """ )
683+ s = Signal (signed (4 ))
684+ self .assertRepr (abs (s ), """
685+ (slice (m (>= (sig s) (const 1'd0)) (sig s) (- (sig s))) 0:4)
686+ """ )
687+ self .assertEqual (abs (s ).shape (), unsigned (4 ))
688+
678689
679690class SliceTestCase (FHDLTestCase ):
680691 def test_shape (self ):
You can’t perform that action at this time.
0 commit comments