-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyMath.jack
40 lines (34 loc) · 815 Bytes
/
MyMath.jack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class MyMath {
//x%y
function int mod(int x, int y) {
return (x - (y * (x/y)) );
}
//returns x/y, rounded up if there is any remainder
function int ceilDiv(int x, int y) {
var int quot, ret;
let quot = x/y;
if (MyMath.mod(x, y)) {
return quot + 1;
}
return quot;
}
//returns rounded quotient (5 rounds down)
function int roundDiv(int x, int y) {
var int quot, r, ret;
let quot = x/y;
if (MyMath.mod(x,y) > (quot/2)) {
return quot + 1;
}
return quot;
}
//x**y
function int pow(int x, int y) {
var int ret;
let ret = 1;
while (y > 0) {
let ret = ret * x;
let y = y - 1;
}
return ret;
}
}