-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathInt.js
86 lines (75 loc) · 1.69 KB
/
Int.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
import * as $$Array from "./Array.js";
function fromString(x, radix) {
let maybeInt = radix !== undefined ? parseInt(x, radix) : parseInt(x);
if (isNaN(maybeInt) || maybeInt > 2147483647 || maybeInt < -2147483648) {
return;
} else {
return maybeInt | 0;
}
}
function abs(x) {
if (x >= 0) {
return x;
} else {
return -x | 0;
}
}
function range(start, end, optionsOpt) {
let options = optionsOpt !== undefined ? optionsOpt : ({});
let isInverted = start > end;
let n = options.step;
let step;
if (n !== undefined) {
if (n !== 0) {
step = n;
} else {
if (start !== end) {
throw new RangeError("Incorrect range arguments");
}
step = n;
}
} else {
step = isInverted ? -1 : 1;
}
let length;
if (isInverted === step >= 0) {
length = 0;
} else if (step === 0) {
length = options.inclusive === true ? 1 : 0;
} else {
let range$1 = isInverted ? start - end | 0 : end - start | 0;
let range$2 = options.inclusive === true ? range$1 + 1 | 0 : range$1;
length = Math.ceil(range$2 / abs(step)) | 0;
}
return $$Array.fromInitializer(length, i => start + Math.imul(i, step) | 0);
}
function rangeWithOptions(start, end, options) {
return range(start, end, options);
}
function clamp(min, max, value) {
let value$1 = max !== undefined && max < value ? max : value;
if (min !== undefined && min > value$1) {
return min;
} else {
return value$1;
}
}
function lnot(x) {
return x ^ -1;
}
let Bitwise = {
lnot: lnot
};
let Constants = {
minValue: -2147483648,
maxValue: 2147483647
};
export {
Constants,
fromString,
range,
rangeWithOptions,
clamp,
Bitwise,
}
/* No side effect */