-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcut-corners.js
86 lines (83 loc) · 1.53 KB
/
cut-corners.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function round(int) {
let neg = false;
if (int < 0) {
neg = true;
int = -int;
}
let counter = 0;
while (!(int < 1 && int > -1)) {
int -= 1;
counter++;
}
if (int < 0.5) {
if (neg) {
return -counter;
} else {
return counter;
}
} else {
if (neg) {
return -counter - 1;
} else {
return counter + 1;
}
}
}
function floor(int) {
let neg = false;
if (int < 0) {
neg = true;
int = -int;
}
let intCopy = int;
let counter = 0;
while (!(intCopy < 1 && intCopy > -1)) {
intCopy -= 1;
counter++;
}
if (neg) {
return -counter - 1;
} else {
return counter;
}
}
function ceil(int) {
if (!int) return 0;
let neg = false;
if (int < 0) {
neg = true;
int = -int;
}
let intCopy = int;
let counter = 0;
while (!(intCopy < 1 && intCopy >= 0)) {
intCopy -= 1;
counter++;
}
if (neg) {
return -counter;
} else {
return counter + 1;
}
}
function trunc(int) {
let counter = 0;
if (int > 0xfffffffff) {
int -= 0xfffffffff;
counter += 0xfffffffff;
}
let neg = false;
if (int < 0) {
neg = true;
int = -int;
}
let intCopy = int;
while (!(intCopy < 1 && intCopy > -1)) {
intCopy -= 1;
counter++;
}
if (neg) {
return -counter;
}
return counter;
}