aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/bigint/big_ops3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/math/bigint/big_ops3.cpp')
-rw-r--r--src/lib/math/bigint/big_ops3.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/lib/math/bigint/big_ops3.cpp b/src/lib/math/bigint/big_ops3.cpp
index 48d84c8b4..eed8a29a0 100644
--- a/src/lib/math/bigint/big_ops3.cpp
+++ b/src/lib/math/bigint/big_ops3.cpp
@@ -107,6 +107,9 @@ BigInt operator*(const BigInt& x, const BigInt& y)
*/
BigInt operator/(const BigInt& x, const BigInt& y)
{
+ if(y.sig_words() == 1 && is_power_of_2(y.word_at(0)))
+ return (x >> (y.bits() - 1));
+
BigInt q, r;
divide(x, y, q, r);
return q;
@@ -137,6 +140,9 @@ word operator%(const BigInt& n, word mod)
if(mod == 0)
throw BigInt::DivideByZero();
+ if(mod == 1)
+ return 0;
+
if(is_power_of_2(mod))
return (n.word_at(0) & (mod - 1));