Skip to content

Commit

Permalink
[libc] Fix BigInt's operator %= (#98484)
Browse files Browse the repository at this point in the history
This patch fixes cases where we try to do var %= 1. Previously this operator was calling .div directly since it would perform the inplace division and return the remainder, however, as an early exit condition a division by one returns zero as the remainder. The remainder being returned by div was not being assigned to var.
  • Loading branch information
mikhailramalho committed Jul 11, 2024
1 parent 4a9de11 commit dffa28f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libc/src/__support/big_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ struct BigInt {
}

LIBC_INLINE constexpr BigInt operator%=(const BigInt &other) {
return *this->div(other);
*this = *this % other;
return *this;
}

LIBC_INLINE constexpr BigInt &operator*=(const BigInt &other) {
Expand Down

0 comments on commit dffa28f

Please sign in to comment.