From d46566e16e4097c8672fbdf6445eda15979414c8 Mon Sep 17 00:00:00 2001 From: SecondJochen Date: Fri, 8 May 2026 11:18:51 +0200 Subject: [PATCH 1/2] add modulo operator --- src/vec/base256.h | 13 +++++++++++++ tests/test_base256.cpp | 3 --- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/vec/base256.h b/src/vec/base256.h index c385059..1f23f66 100644 --- a/src/vec/base256.h +++ b/src/vec/base256.h @@ -115,6 +115,19 @@ class Base256 { return *this; } + friend Base256 operator%(const Base256 &rhs, const Base256 &lhs) { + Base256 result(rhs); + result %= lhs; + return result; + } + + Base256 &operator%=(const Base256 &rhs) { + Base256 remaining; + this->div(rhs.data, &remaining.data); + this->data = std::move(remaining.data); + return *this; + } + [[nodiscard]] friend bool operator==(const Base256 &lhs, const Base256 &rhs) { return isEqual(lhs.data, rhs.data); } diff --git a/tests/test_base256.cpp b/tests/test_base256.cpp index cd031e6..2107181 100644 --- a/tests/test_base256.cpp +++ b/tests/test_base256.cpp @@ -222,12 +222,10 @@ TEST_CASE("Base256: division by zero (edge cases)") { SECTION("Dividing zero by zero yields zero") { REQUIRE(make(0) / make(0) == make(0)); } } -// TODO TEST_CASE("Base256: remainder / modulo logic") { // Assuming you have implemented operator% (e.g., a % b) // If not, adapt this to test your exposed remainder API or `div()` method - /* SECTION("Remainder of zero dividend yields zero") { // Tests the interior block: `if (remaining != nullptr) *remaining = {0};` // when `initialDividendIndex < 0` @@ -252,7 +250,6 @@ TEST_CASE("Base256: remainder / modulo logic") { REQUIRE(make(10) % make(20) == make(10)); REQUIRE(make(1) % make(MAX_U64) == make(1)); } - */ } TEST_CASE("Base256: mixed expressions & combinations") { From 31c54b40d4e68e88778d22294db3f4ea1dd781e7 Mon Sep 17 00:00:00 2001 From: SecondJochen <213428453+SecondJochen@users.noreply.github.com> Date: Sun, 24 May 2026 23:08:01 +0000 Subject: [PATCH 2/2] Apply Clang formatting --- tests/test_base256.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_base256.cpp b/tests/test_base256.cpp index 2107181..b656638 100644 --- a/tests/test_base256.cpp +++ b/tests/test_base256.cpp @@ -232,7 +232,6 @@ TEST_CASE("Base256: remainder / modulo logic") { REQUIRE(make(0) % make(123456) == make(0)); } - SECTION("Remainder of division by zero yields zero") { // Tests the interior block: `if (remaining != nullptr) *remaining = {0};` // when `isZero(divisor)`