aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/bigint/big_ops2.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-02-26 07:56:20 -0500
committerJack Lloyd <[email protected]>2018-02-26 07:56:20 -0500
commitac1d24cf06de5e800cbb8a3c7ab392c081aeb783 (patch)
tree43929f0ffc1926af9dd40ed5ee493bc77d4893c2 /src/lib/math/bigint/big_ops2.cpp
parente479bae1d4b66e0984ce7791370e95aa69c4e3f6 (diff)
Add BigInt::operator*= taking a word
Avoids memory allocation when multiplying by a small constant.
Diffstat (limited to 'src/lib/math/bigint/big_ops2.cpp')
-rw-r--r--src/lib/math/bigint/big_ops2.cpp19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/lib/math/bigint/big_ops2.cpp b/src/lib/math/bigint/big_ops2.cpp
index 2f81989c3..7653884c9 100644
--- a/src/lib/math/bigint/big_ops2.cpp
+++ b/src/lib/math/bigint/big_ops2.cpp
@@ -107,12 +107,12 @@ BigInt& BigInt::operator*=(const BigInt& y)
}
else if(x_sw == 1 && y_sw)
{
- grow_to(y_sw + 2);
+ grow_to(y_sw + 1);
bigint_linmul3(mutable_data(), y.data(), y_sw, word_at(0));
}
else if(y_sw == 1 && x_sw)
{
- grow_to(x_sw + 2);
+ grow_to(x_sw + 1);
bigint_linmul2(mutable_data(), x_sw, y.word_at(0));
}
else
@@ -125,6 +125,21 @@ BigInt& BigInt::operator*=(const BigInt& y)
return (*this);
}
+BigInt& BigInt::operator*=(word y)
+ {
+ if(y == 0)
+ {
+ clear();
+ set_sign(Positive);
+ }
+
+ const size_t x_sw = sig_words();
+ grow_to(x_sw + 1);
+ bigint_linmul2(mutable_data(), x_sw, y);
+
+ return (*this);
+ }
+
/*
* Division Operator
*/