From 55b63099a8175f5a5e6f50eb4f789bca0eceda7f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 24 Jun 2026 10:35:36 +0100 Subject: [PATCH] Fix constant `x %% y` evaluation --- src/big_int.cpp | 8 ++++++++ src/exact_value.cpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/big_int.cpp b/src/big_int.cpp index e2ebb5c76..4f20f2ad9 100644 --- a/src/big_int.cpp +++ b/src/big_int.cpp @@ -432,6 +432,14 @@ gb_internal void big_int_rem(BigInt *z, BigInt const *x, BigInt const *y) { big_int_quo_rem(x, y, &q, z); big_int_dealloc(&q); } +gb_internal void big_int_mod_mod(BigInt *z, BigInt const *x, BigInt const *y) { + BigInt q = {}; + big_int_rem(&q, x, y); + big_int_add(&q, &q, y); + big_int_rem(z, &q, y); + big_int_dealloc(&q); + +} gb_internal void big_int_euclidean_mod(BigInt *z, BigInt const *x, BigInt const *y) { BigInt y0 = {}; diff --git a/src/exact_value.cpp b/src/exact_value.cpp index fa26ec4b0..f232f95e0 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -780,7 +780,7 @@ gb_internal ExactValue exact_binary_operator_value(TokenKind op, ExactValue x, E case Token_Quo: return exact_value_float(fmod(big_int_to_f64(a), big_int_to_f64(b))); case Token_QuoEq: big_int_quo(&c, a, b); break; // NOTE(bill): Integer division case Token_Mod: big_int_rem(&c, a, b); break; - case Token_ModMod: big_int_euclidean_mod(&c, a, b); break; + case Token_ModMod: big_int_mod_mod(&c, a, b); break; case Token_And: big_int_and(&c, a, b); break; case Token_Or: big_int_or(&c, a, b); break; case Token_Xor: big_int_xor(&c, a, b); break;