From 3571f998b28fbc8d9250ba04c983935f10a16c15 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 20 Jan 2018 15:02:59 +0100 Subject: removed dat files --- projects/12/Math.jack | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'projects/12/Math.jack') diff --git a/projects/12/Math.jack b/projects/12/Math.jack index 61e09fc..01bce8f 100644 --- a/projects/12/Math.jack +++ b/projects/12/Math.jack @@ -28,6 +28,18 @@ class Math { return ~(x & twoToThe[i] = 0); } + function int sign(int x) { + if (x > 0) { + return 1; + } else { + if (x < 0) { + return -1; + } else { + return 0; + } + } + } + /** Returns the absolute value of x. */ function int abs(int x) { if (x > 0){ @@ -43,11 +55,12 @@ class Math { * the Jack expressions x*y and multiply(x,y) return the same value. */ function int multiply(int x, int y) { - var int z, res, shiftedX, i; + var int res, shiftedX, i; let shiftedX = x; let i = 0; let res = 0; - while ((twoToThe[i] > x) & (i < 16)) { + //while ((~(twoToThe[i] > y)) & (i < 16)) { + while (i < 16) { if (Math.bit(y, i)){ let res = res + shiftedX; } @@ -117,7 +130,7 @@ class Math { while (~(k < 0)) { let z = y + twoToThe[k]; let w = z * z; - if ((w < x) & (w > 0)) { + if ((~(w > x)) & (w > 0)) { let y = z; } let k = k - 1; -- cgit v1.2.3