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
17 changes: 0 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,5 @@ int main(int argc, char* argv[]) {
cli::help();
}

//std::vector<uint8_t> num1 = operations::convertToVector(55555555);
//std::vector<uint8_t> num2 = operations::convertToVector(45678);

// 00010000 00000000 00000000 00000000
std::vector<uint8_t> num1 = {0b00000000, 0b00000000, 0b00000000, 0b00010000};
// 00000000 00000100 00000000 00000000
std::vector<uint8_t> num2 = {0b00000000, 0b00000000, 0b00000100};

std::vector<uint8_t> result = operations::mul(num1, num2);
std::cout << operations::isBigger(num1, num2) << std::endl;

// This prints out the result as a hex number
for (auto it = result.rbegin(); it != result.rend(); ++it) {
printf("%02X", *it);
}
std::cout << std::endl;

return 0;
}
18 changes: 17 additions & 1 deletion src/vec/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ namespace operations {

[[nodiscard]] std::vector<std::uint8_t> div(
const std::vector<std::uint8_t> dividend,
const std::vector<std::uint8_t> &divisor) noexcept {
const std::vector<std::uint8_t> &divisor,
std::vector<std::uint8_t> *remaining = nullptr) noexcept
{
std::vector<std::uint8_t> quotient;
std::uint8_t quotientBuffer = 0;
std::uint16_t quotientBitIndex = 0;
Expand All @@ -289,6 +291,17 @@ namespace operations {
}

if (isEqual(dividendMask, divisor) || isBigger(dividendMask, divisor)) {

/* Stop the loop if the dividend is smaller than the divisor, because fractional
* digits are not supported */
if (dividendIndex < 0) {
quotientBuffer <<= 1;

// If remaining pointer is passed, set the remaining value
if (remaining != nullptr) *remaining = dividendMask;
break;
}

// Shift the dividend and set the new bit as high
quotientBuffer <<= 1;
quotientBuffer++;
Expand All @@ -301,6 +314,9 @@ namespace operations {
* digits are not supported */
if (dividendIndex < 0) {
quotientBuffer <<= 1;

// If remaining pointer is passed, set the remaining value
if (remaining != nullptr) *remaining = dividendMask;
break;
}

Expand Down
Loading