forked from rescript-lang/rescript-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore__Int.mjs
88 lines (78 loc) · 1.81 KB
/
Core__Int.mjs
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
87
88
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Core__Array from "./Core__Array.mjs";
function fromString(x, radix) {
var 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) {
var options = optionsOpt !== undefined ? optionsOpt : ({});
var isInverted = start > end;
var n = options.step;
var 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;
}
var length;
if (isInverted === step >= 0) {
length = 0;
} else if (step === 0) {
length = options.inclusive === true ? 1 : 0;
} else {
var range$1 = isInverted ? start - end | 0 : end - start | 0;
var range$2 = options.inclusive === true ? range$1 + 1 | 0 : range$1;
length = Math.ceil(range$2 / abs(step)) | 0;
}
return Core__Array.fromInitializer(length, (function (i) {
return start + Math.imul(i, step) | 0;
}));
}
function rangeWithOptions(start, end, options) {
return range(start, end, options);
}
function clamp(min, max, value) {
var 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;
}
var Bitwise = {
lnot: lnot
};
var Constants = {
minValue: -2147483648,
maxValue: 2147483647
};
export {
Constants ,
fromString ,
range ,
rangeWithOptions ,
clamp ,
Bitwise ,
}
/* No side effect */