fix sign for alised var for Vint::quotRem

2merge^2
MITSUNARI Shigeo 4 years ago
parent dcd5404185
commit 3c4abd4c3c
  1. 6
      include/mcl/vint.hpp
  2. 27
      test/vint_test.cpp

@ -1544,10 +1544,12 @@ public:
*/
static void quotRem(VintT *q, VintT& r, const VintT& x, const VintT& y)
{
assert(q != &r);
VintT yy = y;
bool qsign = x.isNeg_ ^ y.isNeg_;
bool yNeg = y.isNeg_;
bool qsign = x.isNeg_ ^ yNeg;
udiv(q, r, x.buf_, x.size(), y.buf_, y.size());
r.isNeg_ = y.isNeg_;
r.isNeg_ = yNeg;
if (q) q->isNeg_ = qsign;
if (!r.isZero() && qsign) {
if (q) {

@ -973,6 +973,33 @@ CYBOZU_TEST_AUTO(Vint)
CYBOZU_TEST_EQUAL(q2, tbl[i].q2);
CYBOZU_TEST_EQUAL(r2, tbl[i].r2);
CYBOZU_TEST_EQUAL(q2 * b + r2, a);
r2 = 0;
Vint::quotRem(&b, r2, a, b);
CYBOZU_TEST_EQUAL(b, tbl[i].q2);
CYBOZU_TEST_EQUAL(r2, tbl[i].r2);
b = tbl[i].b;
r2 = 0;
Vint::quotRem(&a, r2, a, b);
CYBOZU_TEST_EQUAL(a, tbl[i].q2);
CYBOZU_TEST_EQUAL(r2, tbl[i].r2);
a = tbl[i].a;
q = 0;
Vint::quotRem(&q, a, a, b);
CYBOZU_TEST_EQUAL(q, tbl[i].q2);
CYBOZU_TEST_EQUAL(a, tbl[i].r2);
a = tbl[i].a;
q = 0;
Vint::quotRem(&q, a, a, b);
CYBOZU_TEST_EQUAL(q, tbl[i].q2);
CYBOZU_TEST_EQUAL(a, tbl[i].r2);
a = tbl[i].a;
q = 0;
Vint::quotRem(&q, b, a, b);
CYBOZU_TEST_EQUAL(q, tbl[i].q2);
CYBOZU_TEST_EQUAL(b, tbl[i].r2);
Vint::quotRem(&q, a, a, a);
CYBOZU_TEST_EQUAL(q, 1);
CYBOZU_TEST_EQUAL(a, 0);
}
CYBOZU_TEST_EQUAL(Vint("15") / Vint("3"), Vint("5"));
CYBOZU_TEST_EQUAL(Vint("15") / Vint("-3"), Vint("-5"));

Loading…
Cancel
Save