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):
263
263
264
264
def __abs__ (self ):
265
265
if self .shape ().signed :
266
- return Mux (self >= 0 , self , - self )
266
+ return Mux (self >= 0 , self , - self )[: len ( self )]
267
267
else :
268
268
return self
269
269
Original file line number Diff line number Diff line change @@ -675,6 +675,17 @@ def test_hash(self):
675
675
with self .assertRaises (TypeError ):
676
676
hash (Const (0 ) + Const (0 ))
677
677
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
+
678
689
679
690
class SliceTestCase (FHDLTestCase ):
680
691
def test_shape (self ):
You can’t perform that action at this time.
0 commit comments