Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/vec/base256.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 0 additions & 4 deletions tests/test_base256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand All @@ -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") {
Expand Down