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..b656638 100644 --- a/tests/test_base256.cpp +++ b/tests/test_base256.cpp @@ -222,19 +222,16 @@ 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` 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)` @@ -252,7 +249,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") {