Skip to content

Commit dffa28f

Browse files
[libc] Fix BigInt's operator %= (#98484)
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.
1 parent 4a9de11 commit dffa28f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libc/src/__support/big_int.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,8 @@ struct BigInt {
732732
}
733733

734734
LIBC_INLINE constexpr BigInt operator%=(const BigInt &other) {
735-
return *this->div(other);
735+
*this = *this % other;
736+
return *this;
736737
}
737738

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

0 commit comments

Comments
 (0)