You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/primitive-types.mdx
+89
Original file line number
Diff line number
Diff line change
@@ -166,6 +166,95 @@ var result = 1 + 2;
166
166
167
167
</CodeTab>
168
168
169
+
## Big Integers (experimental)
170
+
171
+
**Since 11.1**
172
+
173
+
For values which are too large to be represented by Int or Float, there is the `bigint` primitive type.
174
+
We provide the usual operations on them: `+`, `-`, `*`, `/`, etc. See [BigInt](api/core/bigint) for helper functions.
175
+
176
+
A `bigint` number is denoted by a trailing `n` like so: `42n`.
177
+
178
+
As `bigint` is a different data type than `int`, it's necessary to open the corresponding module to overload the operators.
179
+
180
+
<CodeTablabels={["ReScript", "JS Output"]}>
181
+
182
+
```res example
183
+
open! Js.BigInt
184
+
185
+
let a = 9007199254740991n + 9007199254740991n
186
+
let b = 2n ** 2n
187
+
```
188
+
```js
189
+
var a =9007199254740991n+9007199254740991n;
190
+
191
+
var p =2n**2n;
192
+
```
193
+
194
+
</CodeTab>
195
+
196
+
It also supports all the bitwise operations, except unsigned shift right (`>>>`), which is not supported by JS itself for `bigint`s.
197
+
198
+
<CodeTablabels={["ReScript", "JS Output"]}>
199
+
200
+
```res example
201
+
open! Js.BigInt
202
+
203
+
let a = land(1n, 1n)
204
+
let b = lor(1n, 1n)
205
+
let c = lxor(1n, 1n)
206
+
let d = lnot(1n)
207
+
let e = lsl(1n, 1n)
208
+
let f = asr(1n, 1n)
209
+
```
210
+
```js
211
+
var Js_bigint =require("./stdlib/js_bigint.js");
212
+
213
+
var a =1n&1n;
214
+
215
+
var b =1n|1n;
216
+
217
+
var c =1n^1n;
218
+
219
+
var d =Js_bigint.lnot(1n);
220
+
221
+
var e = (1n<<1n);
222
+
223
+
var f = (1n>>1n);
224
+
```
225
+
226
+
</CodeTab>
227
+
228
+
It can also be pattern-matched.
229
+
230
+
<CodeTablabels={["ReScript", "JS Output"]}>
231
+
232
+
```res example
233
+
let bigintValue = 1n
234
+
235
+
switch bigintValue {
236
+
| 1n => Console.log("Small bigint")
237
+
| 100n => Console.log("Larger bigint")
238
+
| _ => Console.log("Other bigint")
239
+
}
240
+
```
241
+
```js
242
+
if (1n!==1n) {
243
+
if (1n!==100n) {
244
+
console.log("Other bigint");
245
+
} else {
246
+
console.log("Larger bigint");
247
+
}
248
+
} else {
249
+
console.log("Small bigint");
250
+
}
251
+
252
+
var bigintValue =1n;
253
+
```
254
+
255
+
</CodeTab>
256
+
257
+
169
258
## Unit
170
259
171
260
The `unit` type indicates the absence of a specific value. It has only a single value, `()`, which acts as a placeholder when no other value exists or is needed. It compiles to JavaScript's `undefined` and resembles the `void` type in languages such as C++. What's the point of such a type?
Copy file name to clipboardExpand all lines: pages/docs/manual/latest/variant.mdx
+1
Original file line number
Diff line number
Diff line change
@@ -365,6 +365,7 @@ Here's a list of all possible things you can unbox:
365
365
-`string`: `String(string)`
366
366
-`float`: `Float(float)`. Note you can only have one of `float` or `int` because JavaScript only has `number` (not actually `int` and `float` like in ReScript) so we can't disambiguate between `float` and `int` at runtime.
367
367
-`int`: `Int(int)`. See note above on `float`.
368
+
-`bigint`: `BigInt(int)`. **Since 11.1** This is a distinct type from JavaScript's `number` type so you can use it beside either `float` or `int`.
368
369
-`bool`: `Boolean(bool)`
369
370
-`array<'value>`: `List(array<string>)`
370
371
-`('a, 'b, 'c)`: `Tuple((string, int, bool))`. Any size of tuples works, but you can have only one case of array or tuple in a variant.
0 commit comments