1
- /**
2
- Type representing a bigint.
3
- */
4
1
type t = bigint
5
2
6
3
@val external asIntN : (~width : int , bigint ) => bigint = "BigInt.asIntN"
7
4
@val external asUintN : (~width : int , bigint ) => bigint = "BigInt.asUintN"
8
5
9
- /**
10
- Parses the given `string` into a `bigint` using JavaScript semantics. Return the
11
- number as a `bigint` if successfully parsed. Throws a syntax exception otherwise.
12
-
13
- ## Examples
14
-
15
- ```rescript
16
- BigInt.fromStringOrThrow("123")->assertEqual(123n)
17
-
18
- BigInt.fromStringOrThrow("")->assertEqual(0n)
19
-
20
- BigInt.fromStringOrThrow("0x11")->assertEqual(17n)
21
-
22
- BigInt.fromStringOrThrow("0b11")->assertEqual(3n)
23
-
24
- BigInt.fromStringOrThrow("0o11")->assertEqual(9n)
25
-
26
- /* catch exception */
27
- switch BigInt.fromStringOrThrow("a") {
28
- | exception JsExn(_error) => assert(true)
29
- | _bigInt => assert(false)
30
- }
31
- ```
32
- */
33
6
@val
34
7
external fromStringOrThrow : string => bigint = "BigInt"
35
8
36
- /**
37
- Parses the given `string` into a `bigint` using JavaScript semantics. Returns
38
- `Some(bigint)` if the string can be parsed, `None` otherwise.
39
-
40
- ## Examples
41
-
42
- ```rescript
43
- BigInt.fromString("123")->assertEqual(Some(123n))
44
-
45
- BigInt.fromString("")->assertEqual(Some(0n))
46
-
47
- BigInt.fromString("0x11")->assertEqual(Some(17n))
48
-
49
- BigInt.fromString("0b11")->assertEqual(Some(3n))
50
-
51
- BigInt.fromString("0o11")->assertEqual(Some(9n))
52
-
53
- BigInt.fromString("invalid")->assertEqual(None)
54
- ```
55
- */
56
9
let fromString = (value : string ) => {
57
10
try Some (fromStringOrThrow (value )) catch {
58
11
| _ => None
@@ -64,26 +17,6 @@ external fromStringExn: string => bigint = "BigInt"
64
17
65
18
@val external fromInt : int => bigint = "BigInt"
66
19
67
- /**
68
- Converts a `float` to a `bigint` using JavaScript semantics.
69
- Throws an exception if the float is not an integer or is infinite/NaN.
70
-
71
- ## Examples
72
-
73
- ```rescript
74
- BigInt.fromFloatOrThrow(123.0)->assertEqual(123n)
75
-
76
- BigInt.fromFloatOrThrow(0.0)->assertEqual(0n)
77
-
78
- BigInt.fromFloatOrThrow(-456.0)->assertEqual(-456n)
79
-
80
- /* This will throw an exception */
81
- switch BigInt.fromFloatOrThrow(123.5) {
82
- | exception JsExn(_error) => assert(true)
83
- | _bigInt => assert(false)
84
- }
85
- ```
86
- */
87
20
@val
88
21
external fromFloatOrThrow : float => bigint = "BigInt"
89
22
@@ -93,31 +26,12 @@ let fromFloat = (value: float) => {
93
26
}
94
27
}
95
28
96
- /**
97
- Formats a `bigint` as a string. Return a `string` representing the given value.
98
- See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.
99
-
100
- ## Examples
101
-
102
- ```rescript
103
- BigInt.toString(123n)->assertEqual("123")
104
- ```
105
- */
106
29
@send
107
30
external toString : (bigint , ~radix : int = ?) => string = "toString"
108
31
109
32
@deprecated ("Use `toString` with `~radix` instead" ) @send
110
33
external toStringWithRadix : (bigint , ~radix : int ) => string = "toString"
111
34
112
- /**
113
- Returns a string with a language-sensitive representation of this BigInt value.
114
-
115
- ## Examples
116
-
117
- ```rescript
118
- BigInt.toString(123n)->assertEqual("123")
119
- ```
120
- */
121
35
@send
122
36
external toLocaleString : bigint => string = "toLocaleString"
123
37
@@ -140,12 +54,6 @@ external bitwiseNot: bigint => bigint = "%bitnot_bigint"
140
54
external shiftLeft : (bigint , bigint ) => bigint = "%lslbigint"
141
55
external shiftRight : (bigint , bigint ) => bigint = "%asrbigint"
142
56
143
- /**
144
- `ignore(bigint)` ignores the provided bigint and returns unit.
145
-
146
- This helper is useful when you want to discard a value (for example, the result of an operation with side effects)
147
- without having to store or process it further.
148
- */
149
57
external ignore : bigint => unit = "%ignore"
150
58
151
59
@deprecated ("Use `&` operator or `bitwiseAnd` instead." )
0 commit comments