aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-23 07:13:31 -0500
committerJack Lloyd <[email protected]>2018-02-23 07:13:31 -0500
commit971749b8486e4a17eba54c32a8fdff942eb37af2 (patch)
treec7a325814c8a7ceb861284acaffdb1e62d4a9bc0 /src
parent1152261ca45a55f368ea31aa9a5eb89d9c35abc4 (diff)
Fix an error in BigInt operator-
(x) - (-x) would result in -2x instead of the correct 2x
Diffstat (limited to 'src')
-rw-r--r--src/lib/math/bigint/big_ops3.cpp1
-rw-r--r--src/tests/data/bn/add.vec26
-rw-r--r--src/tests/data/bn/sub.vec38
3 files changed, 59 insertions, 6 deletions
diff --git a/src/lib/math/bigint/big_ops3.cpp b/src/lib/math/bigint/big_ops3.cpp
index eed8a29a0..680eca635 100644
--- a/src/lib/math/bigint/big_ops3.cpp
+++ b/src/lib/math/bigint/big_ops3.cpp
@@ -66,6 +66,7 @@ BigInt operator-(const BigInt& x, const BigInt& y)
{
if(x.sign() != y.sign())
bigint_shl2(z.mutable_data(), x.data(), x_sw, 0, 1);
+ z.set_sign(y.reverse_sign());
}
else if(relative_size > 0)
{
diff --git a/src/tests/data/bn/add.vec b/src/tests/data/bn/add.vec
index d7fb72d57..4829e1706 100644
--- a/src/tests/data/bn/add.vec
+++ b/src/tests/data/bn/add.vec
@@ -15,9 +15,29 @@ In1 = 0x1
In2 = 0x1
Output = 0x2
-In1 = 0x1
-In2 = -0x1
-Output = 0x0
+In1 = 1
+In2 = -1
+Output = 0
+
+In1 = -1
+In2 = 1
+Output = 0
+
+In1 = -1
+In2 = -1
+Output = -2
+
+In1 = 1
+In2 = -2
+Output = -1
+
+In1 = -2
+In2 = 1
+Output = -1
+
+In1 = -2
+In2 = -1
+Output = -3
In1 = 0x5
In2 = 0x0
diff --git a/src/tests/data/bn/sub.vec b/src/tests/data/bn/sub.vec
index 5b649ef87..a3cac4206 100644
--- a/src/tests/data/bn/sub.vec
+++ b/src/tests/data/bn/sub.vec
@@ -7,9 +7,41 @@ In1 = 0x0
In2 = 0x1
Output = -0x1
-In1 = 0x1
-In2 = -0x1
-Output = 0x2
+In1 = 1
+In2 = -1
+Output = 2
+
+In1 = -1
+In2 = 1
+Output = -2
+
+In1 = -1
+In2 = -1
+Output = 0
+
+In1 = 1
+In2 = 1
+Output = 0
+
+In1 = 1
+In2 = -1
+Output = 2
+
+In1 = 1
+In2 = -2
+Output = 3
+
+In1 = -1
+In2 = 2
+Output = -3
+
+In1 = -3
+In2 = -1
+Output = -2
+
+In1 = -3
+In2 = 1
+Output = -4
In1 = 0x64
In2 = -0x64