From 2d20920f234dedf8ee080d9e0a7e097096bb77b0 Mon Sep 17 00:00:00 2001 From: Naoki Shibata Date: Sat, 7 Sep 2024 00:26:09 +0900 Subject: [PATCH] no message --- src/include/tlfloat/bigint.hpp | 2 +- src/tester/test_bigint2.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/include/tlfloat/bigint.hpp b/src/include/tlfloat/bigint.hpp index 03e0c49..ac6313e 100644 --- a/src/include/tlfloat/bigint.hpp +++ b/src/include/tlfloat/bigint.hpp @@ -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 divmod(const BigUInt& rhs, const BigUInt& recip) const { - if (rhs == 1) xpair(*this, 0); + if (rhs == 1) return xpair(*this, 0); BigUInt q = this->mulhi(recip), m = *this - q * rhs; if (!(rhs > m)) { q++; m = m - rhs; } return xpair(q, m); diff --git a/src/tester/test_bigint2.cpp b/src/tester/test_bigint2.cpp index 9d2bcc2..1869466 100644 --- a/src/tester/test_bigint2.cpp +++ b/src/tester/test_bigint2.cpp @@ -90,6 +90,17 @@ void doTestDivmod2(BigUInt n, BigUInt 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); + } } } @@ -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>();