multiplication: fixed rest part

This commit is contained in:
2017-07-31 13:03:18 -04:00
parent c3c04b558a
commit 8bf048b53d
2 changed files with 5 additions and 5 deletions

View File

@@ -63,8 +63,8 @@ silly silly_mul(silly x, silly y) {
z.sign = x.sign ^ y.sign; z.sign = x.sign ^ y.sign;
uint64_t t0 = (x.before * y.after); uint64_t t0 = ((uint64_t) x.before) * y.after;
uint64_t t1 = (y.before * x.after); uint64_t t1 = ((uint64_t) y.before) * x.after;
z.before = x.before * y.before + (t0>>32) + (t1>>32); z.before = x.before * y.before + (t0>>32) + (t1>>32);
uint32_t t0b = t0&0xffffffff; uint32_t t0b = t0&0xffffffff;
uint32_t t1b = t1&0xffffffff; uint32_t t1b = t1&0xffffffff;

View File

@@ -81,13 +81,13 @@ TEST silly_multiplication() {
x = silly_zeros(); x = silly_zeros();
x.before = 3; x.before = 3;
x.after = 0xffffffff; x.after = 1<<31;
y = silly_zeros(); y = silly_zeros();
y.before = 2; y.before = 2;
x = silly_mul(x, y); x = silly_mul(x, y);
/*ASSERT_EQ_FMT(7, x.before, "%d"); ASSERT_EQ_FMT(7, x.before, "%d");
ASSERT_EQ_FMT(0, x.after, "%d");*/ ASSERT_EQ_FMT(0, x.after, "%d");
PASS(); PASS();
} }