summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--number.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/number.cpp b/number.cpp
index 94ef1ee..c3dd33c 100644
--- a/number.cpp
+++ b/number.cpp
@@ -151,13 +151,22 @@ number::operator*(const number &n) const
number
number::operator<<(std::uint32_t shift) const
{
- if (shift > 32) {
- /* TODO */
- throw std::out_of_range("> 32");
+ if (*this == 0) {
+ return 0;
}
number result(*this);
+ /*
+ * Since, internally, we store 32-bits-wide integers, we can just insert
+ * "shift / 32" new integers at the beginning.
+ */
+ for (unsigned int i = 0; i < shift / 32; ++i) {
+ result._operands.push_front(0);
+ }
+
+ shift %= 32;
+
std::uint32_t carry = 0;
for (auto &operand: result._operands) {