From 9d1a8c5b61686493b5ed6ca2bca326d67093c69c Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Mon, 8 Apr 2019 09:10:02 +0000 Subject: [PATCH] more test cases --- moo/kernel/test-001.moo | 5 +++++ moo/lib/bigint.c | 8 ++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/moo/kernel/test-001.moo b/moo/kernel/test-001.moo index fa3010f..eef2b66 100644 --- a/moo/kernel/test-001.moo +++ b/moo/kernel/test-001.moo @@ -379,13 +379,18 @@ extend MyObject [ self testBigintDiv: 100919283908998345873248972389472389791283789123712899089034258903482398198123912831 divisor: 129323482374892374238974238974238947328972389128387312892713891728391278 count: 2000 ], [ self testBigintDiv: 234897230919283908998345873248972389472389791283789123712899089034258903482398198123912831 divisor: 12932348237489237423897423897423894732897238912838731289271389172839127 count: 2000 ], [ self testBigintDiv: 16r1234567812345678123456781234567812345678123456781234567812345678123456781234567812345678 divisor: 16r12345678123456781234567812345678123456781234567812345678 count: 2000 ], + + ## 155-159 [ self testBigintDiv: 16r000089ab0000456700000123 divisor: 1 count: 2000 ], [ self testBigintDiv: 16r000000030000000000008000 divisor: 16r000000010000000000002000 count: 2000 ], [ self testBigintDiv: 16rfffffffe0000000080000000 divisor: 16r0000ffff0000000080000000 count: 12345 ], [ self testBigintDiv: 16rfffffffffffffffe divisor: 16rffffffff count: 2000 ], [ self testBigintDiv: 68651967526299315528548877601614136727014 divisor: 1729382256910270380 count: 1 ], + + ## 160-164 [ self testBigintDiv: 43943618413704592900396132847030223073729048496 divisor: 1135814937804493543741046072006331 count: 1 ], [ self testBigintDiv: 76733673740671314025981152630586699414203 divisor: 12682136550675277273 count: 1 ], + [ self testBigintDiv: 265804060782114895959697138188904455994 divisor: 713053462628379038341886861235 count: 1], ## ========================= diff --git a/moo/lib/bigint.c b/moo/lib/bigint.c index 7a91d6e..9e803fa 100644 --- a/moo/lib/bigint.c +++ b/moo/lib/bigint.c @@ -1727,22 +1727,18 @@ static MOO_INLINE moo_liw_t calculate_remainder (moo_t* moo, moo_liw_t* qr, moo_ for (b = 0, c = 0, c2 = 0, j = qr_start, k = 0; k < stop; j++, k++) { - /* qr[j] = xmy(qr[j], 0, b); */ dw = (moo_lidw_t)qr[j] - b; b = (moo_liw_t)((dw >> MOO_LIW_BITS) & 1); /* b = -(dw mod BASE) */ qr[j] = (moo_liw_t)dw; - /* moo_liw_t qyk = axpy(q, divisor[k], 0, c); */ dw = ((moo_lidw_t)y[k] * quo) + c; c = (moo_liw_t)(dw >> MOO_LIW_BITS); qyk = (moo_liw_t)dw; - /*c2 = 0; qr[j] = xmy(qr[j], qyk, c2); */ dw = (moo_lidw_t)qr[j] - qyk; c2 = (moo_liw_t)((dw >> MOO_LIW_BITS) & 1); qr[j] = (moo_liw_t)dw; - /*b = xpy(b, c2, c);*/ dw = (moo_lidw_t)b + c2 + c; c = (moo_liw_t)(dw >> MOO_LIW_BITS); b = (moo_liw_t)dw; @@ -1903,6 +1899,7 @@ static void divide_unsigned_array2 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs */ for (i = 0; i < ys; i++) { r[i] = q[i]; q[i] = 0; } for (; i <= xs; i++) { q[i - ys] = q[i]; q[i] = 0; } + } static void divide_unsigned_array3 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs, const moo_liw_t* y, moo_oow_t ys, moo_liw_t* q, moo_liw_t* r) @@ -1992,8 +1989,8 @@ static void divide_unsigned_array3 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs { dw = qhat * r[k]; di = qq[i] - ci - (dw & MOO_TYPE_MAX(moo_liw_t)); - qq[i] = di; ci = (dw >> MOO_LIW_BITS) - (di >> MOO_LIW_BITS); + qq[i] = (moo_liw_t)di; } MOO_ASSERT (moo, i == j); di = qq[j] - ci; @@ -2012,7 +2009,6 @@ static void divide_unsigned_array3 (moo_t* moo, const moo_liw_t* x, moo_oow_t xs MOO_ASSERT (moo, i == j); /*MOO_ASSERT (moo, ci == 1);*/ qq[j] += ci; - q[g] = qhat - 1; } else