-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrc-math.js
More file actions
39 lines (30 loc) · 793 Bytes
/
rc-math.js
File metadata and controls
39 lines (30 loc) · 793 Bytes
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
const b_encoding = '0123456789!#$%&()*+,-./;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
const b_len = b_encoding.length
function i2s_s(value, length) {
if (typeof length === 'undefined') {
length = 0
}
if (value < 0) {
return i2s(-value * 2, length)
}
else {
return i2s(value * 2 + 1, length)
}
}
function i2s(i, length) {
if (typeof length === 'undefined') { length = 0 }
var s = ''
while (i > 0 || length > s.length) {
s = b_encoding.charAt(i % b_len) + s
i = ~~(i / b_len)
}
return s
}
function s2i(s) {
var i = 0
while (s.length) {
i = i * b_len + b_encoding.indexOf(s.charAt(0))
s = s.substr(1, s.length - 1)
}
return i
}