Skip to content

Commit eef78be

Browse files
committed
[libc] Refactor BigInt
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.
1 parent c5f839b commit eef78be

File tree

9 files changed

+837
-737
lines changed

9 files changed

+837
-737
lines changed

libc/src/__support/FPUtil/dyadic_float.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ template <size_t Bits> struct DyadicFloat {
5858
// significant bit.
5959
LIBC_INLINE constexpr DyadicFloat &normalize() {
6060
if (!mantissa.is_zero()) {
61-
int shift_length = static_cast<int>(mantissa.clz());
61+
int shift_length = cpp::countl_zero(mantissa);
6262
exponent -= shift_length;
63-
mantissa.shift_left(static_cast<size_t>(shift_length));
63+
mantissa <<= static_cast<size_t>(shift_length);
6464
}
6565
return *this;
6666
}
@@ -233,7 +233,7 @@ LIBC_INLINE constexpr DyadicFloat<Bits> quick_add(DyadicFloat<Bits> a,
233233
result.sign = a.sign;
234234
result.exponent = a.exponent;
235235
result.mantissa = a.mantissa;
236-
if (result.mantissa.add(b.mantissa)) {
236+
if (result.mantissa.add_overflow(b.mantissa)) {
237237
// Mantissa addition overflow.
238238
result.shift_right(1);
239239
result.mantissa.val[DyadicFloat<Bits>::MantissaType::WORD_COUNT - 1] |=

0 commit comments

Comments
 (0)