From 7ad3746b27ed84700206dcd33f528b5fd773b142 Mon Sep 17 00:00:00 2001 From: "Mikhail R. Gadelha" Date: Wed, 10 Jul 2024 22:24:50 -0300 Subject: [PATCH] [libc] Fix BigInt's operator %= This patch fixes cases where we try to do var %= 1. Previous 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. --- libc/src/__support/big_int.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc/src/__support/big_int.h b/libc/src/__support/big_int.h index 82a5251418854a..8eeb4db9d650ba 100644 --- a/libc/src/__support/big_int.h +++ b/libc/src/__support/big_int.h @@ -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) {