aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math/bigint/bigint.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-04-26 11:40:50 -0400
committerJack Lloyd <[email protected]>2018-04-26 11:40:50 -0400
commitebb73b99a8ca14c45d64de2619ab0cf6b89b860e (patch)
tree082b369de1676755043bf03f4c1d9711ea4eae59 /src/lib/math/bigint/bigint.cpp
parent5860f9db36fcfa0ae7c3c4e768b446106e228f32 (diff)
Add BigInt functions for adding, subtracting and comparing with words
Avoids needless allocations for expressions like x - 1 or y <= 4.
Diffstat (limited to 'src/lib/math/bigint/bigint.cpp')
-rw-r--r--src/lib/math/bigint/bigint.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp
index 8874195af..39cff666c 100644
--- a/src/lib/math/bigint/bigint.cpp
+++ b/src/lib/math/bigint/bigint.cpp
@@ -113,6 +113,18 @@ BigInt::BigInt(RandomNumberGenerator& rng, size_t bits, bool set_high_bit)
randomize(rng, bits, set_high_bit);
}
+int32_t BigInt::cmp_word(word other) const
+ {
+ if(is_negative())
+ return -1; // other is positive ...
+
+ const size_t sw = this->sig_words();
+ if(sw > 1)
+ return 1; // must be larger since other is just one word ...
+
+ return bigint_cmp(this->data(), sw, &other, 1);
+ }
+
/*
* Comparison Function
*/