Skip to content

Commit cf97320

Browse files
committed
- Change README to include bitwise in op list
- Remove trap_leading_zero() calls - Documented XOR loop a bit
1 parent cd05542 commit cf97320

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ arby is designed with the following goals in mind:
3434
- All comparisons
3535
- cast to/from `uintmax_t` and `long double`
3636
- conversion to/from decimal, octal and hexadecimal string
37+
- bitwise operators
3738

3839
### What will be provided in future?
3940

4041
- Additions to **`Nat`**:
41-
- bitwise operators
4242
- bit-shift operators
4343
- Arbitrary-precision signed integers (the [Integers](https://en.wikipedia.org/wiki/Integer)) via class **`Int`**
4444
- All operations supported by **`Nat`** with the exception of bitwise ones

arby/include/arby/Nat.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ namespace com::saxbophone::arby {
619619
for (; it != _digits.end() and rhs_it != rhs._digits.end(); it++, rhs_it++) {
620620
*it |= *rhs_it;
621621
}
622-
_trap_leading_zero(); // XXX: should never trap, TODO: remove
623622
return *this;
624623
}
625624
/**
@@ -685,6 +684,7 @@ namespace com::saxbophone::arby {
685684
auto rhs_it = rhs._digits.begin();
686685
std::size_t l = lhs._digits.size();
687686
std::size_t r = rhs._digits.size();
687+
// consume only one side when it has more unprocessed digits than the other
688688
while (lhs_it != lhs._digits.end() or rhs_it != rhs._digits.end()) {
689689
if (l > r) {
690690
result._digits.push_back(*lhs_it); // XOR with zero = self
@@ -694,9 +694,9 @@ namespace com::saxbophone::arby {
694694
result._digits.push_back(*rhs_it); // XOR with zero = self
695695
r--;
696696
rhs_it++;
697-
} else {
698-
// if the first digit, avoid pushing if zero to avoid leading zeroes
697+
} else { // otherwise, consume both sides
699698
auto answer = *lhs_it ^ *rhs_it;
699+
// if the first digit, avoid pushing if zero to avoid leading zeroes
700700
if (not result._digits.empty() or answer != 0) {
701701
result._digits.push_back(answer);
702702
}
@@ -706,7 +706,6 @@ namespace com::saxbophone::arby {
706706
rhs_it++;
707707
}
708708
}
709-
result._trap_leading_zero(); // XXX: should never trap, TODO: remove
710709
return result;
711710
}
712711
// XXX: unimplemented shift operators commented out until implemented

0 commit comments

Comments
 (0)