-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCore__Int.resi
322 lines (252 loc) · 9.11 KB
/
Core__Int.resi
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
/* Copyright (C) 2015-2016 Bloomberg Finance L.P.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/***
Functions for interacting with JavaScript Number.
See: [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number).
*/
module Constants: {
/**
The smallest positive number represented in JavaScript.
See [`Number.MIN_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MIN_VALUE)
on MDN.
## Examples
```rescript
Console.log(Int.Constants.minValue)
```
*/
@inline
let minValue: int
/**
The largest positive number represented in JavaScript.
See [`Number.MAX_VALUE`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_VALUE)
on MDN.
## Examples
```rescript
Console.log(Int.Constants.maxValue)
```
*/
@inline
let maxValue: int
}
/**
`toExponential(n)` return a `string` representing the given value in exponential
notation.
See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
on MDN.
## Examples
```rescript
Int.toExponential(1000) // "1e+3"
Int.toExponential(-1000) // "-1e+3"
```
*/
@send
external toExponential: int => string = "toExponential"
/**
`toExponential(n, ~digits)` return a `string` representing the given value in
exponential notation. `digits` specifies how many digits should appear after
the decimal point. See [`Number.toExponential`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential)
on MDN.
## Examples
```rescript
Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1"
Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3"
```
## Exceptions
- `RangeError`: If `digits` less than 0 or greater than 10.
*/
@send
external toExponentialWithPrecision: (int, ~digits: int) => string = "toExponential"
/**
`toFixed(n)` return a `string` representing the given value using fixed-point
notation. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
on MDN.
## Examples
```rescript
Int.toFixed(123456) // "123456.00"
Int.toFixed(10) // "10.00"
```
*/
@send
external toFixed: int => string = "toFixed"
/**
`toFixedWithPrecision(n, ~digits)` return a `string` representing the given
value using fixed-point notation. `digits` specifies how many digits should
appear after the decimal point. See [`Number.toFixed`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed)
on MDN.
## Examples
```rescript
Int.toFixed(300, ~digits=4) // "300.0000"
Int.toFixed(300, ~digits=1) // "300.0"
```
## Exceptions
- `RangeError`: If `digits` is less than 0 or larger than 100.
*/
@send
external toFixedWithPrecision: (int, ~digits: int) => string = "toFixed"
/**
`toPrecision(n)` return a `string` representing the giver value with precision.
This function omits the argument that controls precision, so it behaves like
`toString`. See `toPrecisionWithPrecision` to control precision. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
## Examples
```rescript
Int.toPrecision(100) // "100"
Int.toPrecision(1) // "1"
```
*/
@send
external toPrecision: int => string = "toPrecision"
/**
`toPrecision(n, ~digits)` return a `string` representing the giver value with
precision. `digits` specifies the number of significant digits. See [`Number.toPrecision`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) on MDN.
## Examples
```rescript
Int.toPrecision(100, ~digits=2) // "1.0e+2"
Int.toPrecision(1) // "1.0"
```
## Exceptions
- `RangeError`: If `digits` is not between 1 and 100 (inclusive).
Implementations are allowed to support larger and smaller values as well.
ECMA-262 only requires a precision of up to 21 significant digits.
*/
@send
external toPrecisionWithPrecision: (int, ~digits: int) => string = "toPrecision"
/**
`toString(n)` return a `string` representing the given value.
See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
on MDN.
## Examples
```rescript
Int.toString(1000) // "1000"
Int.toString(-1000) // "-1000"
```
*/
@send
external toString: int => string = "toString"
/**
`toStringWithRadix(n, ~radix)` return a `string` representing the given value.
`~radix` specifies the radix base to use for the formatted number.
See [`Number.toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString)
on MDN.
## Examples
```rescript
Int.toString(6, ~radix=2) // "110"
Int.toString(3735928559, ~radix=16) // "deadbeef"
Int.toStringWithRadix(123456, ~radix=36) // "2n9c"
```
## Exceptions
`RangeError`: if `radix` is less than 2 or greater than 36.
*/
@send
external toStringWithRadix: (int, ~radix: int) => string = "toString"
/**
`toLocaleString(n)` return a `string` with language-sensitive representing the
given value. See [`Number.toLocaleString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString) on MDN.
## Examples
```rescript
// If the application uses English as the default language
Int.toLocaleString(1000) // "1,000"
// If the application uses Portuguese Brazil as the default language
Int.toLocaleString(1000) // "1.000"
```
*/
@send
external toLocaleString: int => string = "toLocaleString"
/**
`toFloat(n)` return a `float` representing the given value.
## Examples
```rescript
Int.toFloat(100) == 100.0
Int.toFloat(2) == 2.0
```
*/
external toFloat: int => float = "%identity"
/**
`fromFloat(n)` return an `int` representing the given value. The conversion is
done by truncating the decimal part.
## Examples
```rescript
Int.fromFloat(2.0) == 2
Int.fromFloat(1.999) == 1
Int.fromFloat(1.5) == 1
Int.fromFloat(0.9999) == 0
```
*/
external fromFloat: float => int = "%intoffloat"
/**
`fromString(str)` return an `option<int>` representing the given value 'str'.
## Examples
```rescript
Int.fromString("0") == Some(0)
Int.fromString("NaN") == None
```
*/
let fromString: string => option<int>
/**
`mod(n1, n2)` calculates the modulo (remainder after division) of two integers.
## Examples
```rescript
Int.mod(7, 4) == 3
```
*/
external mod: (int, int) => int = "%modint"
/**
`range(start, end)` returns an int array of the sequence of integers in the
range `[start, end)`. That is, including `start` but excluding `end`.
If `start < end` the sequence will be increasing in steps of 1.
If `start > end` the sequence will be decreasing in steps of -1.
This is equivalent to `rangeWithOptions` with `inclusive` set to `false` and
`step` set to `1` if `start < end` and `-1` otherwise.
## Examples
```rescript
Int.range(3, 6) == [3, 4, 5]
Int.range(-3, -1) == [-3, -2]
Int.range(3, 1) == [3, 2]
```
*/
let range: (int, int) => array<int>
/**
The options for `rangeWithOptions`.
*/
type rangeOptions = {step?: int, inclusive?: bool}
/**
`rangeWithOptions(start, end, options)` is like `range`, but with `step` and
`inclusive` options configurable.
If `step` is set, the sequence will increase or decrease by that amount for each
step. If `start < end` and `step` is negative, or vice versa, an empty array is
returned since the sequence would otherwise never reach or exceed the end value
and hence be infinite. If `step` is `0` and `start !=` end, a `RangeError` is
raised as the sequence would never reach or exceed the end value and hence be
infinite.
If `inclusive` is set to `true`, the sequence will include `end` if `step` is
set such that the sequence includes it.
## Examples
```rescript
Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5]
Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7]
Int.rangeWithOptions(3, 6, {step: -2}) // RangeError
```
## Exceptions
- Raises `RangeError` if `step == 0 && start != end`.
*/
let rangeWithOptions: (int, int, rangeOptions) => array<int>