Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoki Shibata committed Sep 6, 2024
1 parent db5bb9a commit 2d20920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/include/tlfloat/bigint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ namespace tlfloat {

/** This method performs division and modulo at a time. Give rhs.reciprocal() as the second argument */
constexpr TLFLOAT_INLINE xpair<BigUInt, BigUInt> divmod(const BigUInt& rhs, const BigUInt& recip) const {
if (rhs == 1) xpair<BigUInt, BigUInt>(*this, 0);
if (rhs == 1) return xpair<BigUInt, BigUInt>(*this, 0);
BigUInt q = this->mulhi(recip), m = *this - q * rhs;
if (!(rhs > m)) { q++; m = m - rhs; }
return xpair<BigUInt, BigUInt>(q, m);
Expand Down
12 changes: 11 additions & 1 deletion src/tester/test_bigint2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ void doTestDivmod2(BigUInt<N> n, BigUInt<N> d) {
cout << "t.r = " << toHexString(t.second) << endl;
exit(-1);
}

t = n.divmod(d, d.reciprocal());
if (t.second >= d || t.first * d + t.second != n) {
cout << "N = " << N << endl;
cout << "n = " << toHexString(n) << " " << n << endl;
cout << "d = " << toHexString(d) << " " << d << endl;
cout << "d.r = " << toHexString(d.reciprocal()) << endl;
cout << "t.q = " << toHexString(t.first ) << endl;
cout << "t.r = " << toHexString(t.second) << endl;
exit(-1);
}
}
}

Expand Down Expand Up @@ -165,7 +176,6 @@ int main(int argc, char **argv) {
if (argc != 1) n = stoi(argv[1]);
if (argc == 3) ntest = stoi(argv[2]);

testLoop<6>();
testLoop<7>();
testLoop<8>();
testLoop<9>();
Expand Down

0 comments on commit 2d20920

Please sign in to comment.