Skip to content

Commit

Permalink
[libc] Refactor BigInt
Browse files Browse the repository at this point in the history
This patch moves most of the multiprecision logic to the `multiword`
namespace and simplifies some logic in `BigInt`. It also fully
implements the mask and count functions. Additionnally many tests are
added.
  • Loading branch information
gchatelet committed Mar 21, 2024
1 parent c96b61a commit 85dafaa
Show file tree
Hide file tree
Showing 10 changed files with 882 additions and 760 deletions.
2 changes: 1 addition & 1 deletion libc/src/__support/CPP/iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ template <typename Iter> class reverse_iterator {
return lhs.base() <= rhs.base();
}

LIBC_INLINE constexpr iterator_type base() const { current; }
LIBC_INLINE constexpr iterator_type base() const { return current; }

LIBC_INLINE constexpr reference operator*() const {
Iter tmp = current;
Expand Down
6 changes: 3 additions & 3 deletions libc/src/__support/FPUtil/dyadic_float.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ template <size_t Bits> struct DyadicFloat {
// significant bit.
LIBC_INLINE constexpr DyadicFloat &normalize() {
if (!mantissa.is_zero()) {
int shift_length = static_cast<int>(mantissa.clz());
int shift_length = cpp::countl_zero(mantissa);
exponent -= shift_length;
mantissa.shift_left(static_cast<size_t>(shift_length));
mantissa <<= static_cast<size_t>(shift_length);
}
return *this;
}
Expand Down Expand Up @@ -233,7 +233,7 @@ LIBC_INLINE constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
result.sign = a.sign;
result.exponent = a.exponent;
result.mantissa = a.mantissa;
if (result.mantissa.add(b.mantissa)) {
if (result.mantissa.add_overflow(b.mantissa)) {
// Mantissa addition overflow.
result.shift_right(1);
result.mantissa.val[DyadicFloat<Bits>::MantissaType::WORD_COUNT - 1] |=
Expand Down

0 comments on commit 85dafaa

Please sign in to comment.