From 8bf048b53d02ef1051f6021df6525722c5afc9fd Mon Sep 17 00:00:00 2001 From: hellerve Date: Mon, 31 Jul 2017 13:03:18 -0400 Subject: [PATCH] multiplication: fixed rest part --- silly.c | 4 ++-- tests/test.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/silly.c b/silly.c index ad67ace..a163753 100644 --- a/silly.c +++ b/silly.c @@ -63,8 +63,8 @@ silly silly_mul(silly x, silly y) { z.sign = x.sign ^ y.sign; - uint64_t t0 = (x.before * y.after); - uint64_t t1 = (y.before * x.after); + uint64_t t0 = ((uint64_t) x.before) * y.after; + uint64_t t1 = ((uint64_t) y.before) * x.after; z.before = x.before * y.before + (t0>>32) + (t1>>32); uint32_t t0b = t0&0xffffffff; uint32_t t1b = t1&0xffffffff; diff --git a/tests/test.c b/tests/test.c index 16fab9c..e7cac3e 100644 --- a/tests/test.c +++ b/tests/test.c @@ -81,13 +81,13 @@ TEST silly_multiplication() { x = silly_zeros(); x.before = 3; - x.after = 0xffffffff; + x.after = 1<<31; y = silly_zeros(); y.before = 2; x = silly_mul(x, y); - /*ASSERT_EQ_FMT(7, x.before, "%d"); - ASSERT_EQ_FMT(0, x.after, "%d");*/ + ASSERT_EQ_FMT(7, x.before, "%d"); + ASSERT_EQ_FMT(0, x.after, "%d"); PASS(); }