@@ -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