Fix PartitionedSignal.neg and its test case
[ieee754fpu.git] / src / ieee754 / part / test / test_partsig.py
index 8d9a179a66ebe04bf299b6211c23d188e52251fa..7d87eceebac77801362179bdb4a8ca50140ded55 100644 (file)
@@ -280,7 +280,10 @@ class TestPartitionPoints(unittest.TestCase):
                 return result, carry
 
             def test_neg_fn(carry_in, a, b, mask):
-                return test_add_fn(0, a, ~0, mask)
+                lsb = mask & ~(mask - 1)  # has only LSB of mask set
+                pos = lsb.bit_length() - 1  # find bit position
+                a = (a & mask) >> pos  # shift it to the beginning
+                return ((-a) << pos) & mask, 0  # negate and shift it back
 
             def test_op(msg_prefix, carry, test_fn, mod_attr, *mask_list):
                 rand_data = []