-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathInt.js
More file actions
65 lines (57 loc) · 1.36 KB
/
Int.js
File metadata and controls
65 lines (57 loc) · 1.36 KB
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
export const fromNumberImpl = function (just) {
return function (nothing) {
return function (n) {
/* jshint bitwise: false */
return (n | 0) === n ? just(n) : nothing;
};
};
};
export const toNumber = function (n) {
return n;
};
export const fromStringAsImpl = function (just) {
return function (nothing) {
return function (radix) {
var digits;
if (radix < 11) {
digits = "[0-" + (radix - 1).toString() + "]";
} else if (radix === 11) {
digits = "[0-9a]";
} else {
digits = "[0-9a-" + String.fromCharCode(86 + radix) + "]";
}
var pattern = new RegExp("^[\\+\\-]?" + digits + "+$", "i");
return function (s) {
/* jshint bitwise: false */
if (pattern.test(s)) {
var i = parseInt(s, radix);
return (i | 0) === i ? just(i) : nothing;
} else {
return nothing;
}
};
};
};
};
export const toStringAs = function (radix) {
return function (i) {
return i.toString(radix);
};
};
export const quot = function (x) {
return function (y) {
/* jshint bitwise: false */
return x / y | 0;
};
};
export const rem = function (x) {
return function (y) {
return x % y;
};
};
export const pow = function (x) {
return function (y) {
/* jshint bitwise: false */
return Math.pow(x,y) | 0;
};
};