diff options
Diffstat (limited to 'number.cpp')
-rw-r--r-- | number.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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) { |