@grain/stdlib 0.5.13 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +201 -0
  2. package/LICENSE +1 -1
  3. package/README.md +25 -2
  4. package/array.gr +1512 -199
  5. package/array.md +2032 -94
  6. package/bigint.gr +239 -140
  7. package/bigint.md +450 -106
  8. package/buffer.gr +595 -102
  9. package/buffer.md +903 -145
  10. package/bytes.gr +401 -110
  11. package/bytes.md +551 -63
  12. package/char.gr +228 -49
  13. package/char.md +373 -7
  14. package/exception.gr +26 -12
  15. package/exception.md +29 -5
  16. package/float32.gr +130 -109
  17. package/float32.md +185 -57
  18. package/float64.gr +112 -99
  19. package/float64.md +185 -57
  20. package/hash.gr +62 -40
  21. package/hash.md +27 -3
  22. package/int16.gr +430 -0
  23. package/int16.md +618 -0
  24. package/int32.gr +200 -269
  25. package/int32.md +254 -289
  26. package/int64.gr +142 -225
  27. package/int64.md +254 -289
  28. package/int8.gr +511 -0
  29. package/int8.md +786 -0
  30. package/json.gr +2071 -0
  31. package/json.md +646 -0
  32. package/list.gr +120 -68
  33. package/list.md +125 -80
  34. package/map.gr +560 -57
  35. package/map.md +672 -56
  36. package/marshal.gr +239 -227
  37. package/marshal.md +36 -4
  38. package/number.gr +626 -676
  39. package/number.md +738 -153
  40. package/option.gr +33 -35
  41. package/option.md +58 -42
  42. package/package.json +2 -2
  43. package/path.gr +148 -187
  44. package/path.md +47 -96
  45. package/pervasives.gr +75 -416
  46. package/pervasives.md +85 -180
  47. package/priorityqueue.gr +433 -74
  48. package/priorityqueue.md +422 -54
  49. package/queue.gr +362 -80
  50. package/queue.md +433 -38
  51. package/random.gr +67 -75
  52. package/random.md +68 -40
  53. package/range.gr +135 -63
  54. package/range.md +198 -43
  55. package/rational.gr +284 -0
  56. package/rational.md +545 -0
  57. package/regex.gr +933 -1066
  58. package/regex.md +59 -60
  59. package/result.gr +23 -25
  60. package/result.md +54 -39
  61. package/runtime/atof/common.gr +78 -82
  62. package/runtime/atof/common.md +22 -10
  63. package/runtime/atof/decimal.gr +102 -127
  64. package/runtime/atof/decimal.md +28 -7
  65. package/runtime/atof/lemire.gr +56 -71
  66. package/runtime/atof/lemire.md +9 -1
  67. package/runtime/atof/parse.gr +83 -110
  68. package/runtime/atof/parse.md +12 -2
  69. package/runtime/atof/slow.gr +28 -35
  70. package/runtime/atof/slow.md +9 -1
  71. package/runtime/atof/table.gr +19 -18
  72. package/runtime/atof/table.md +10 -2
  73. package/runtime/atoi/parse.gr +153 -136
  74. package/runtime/atoi/parse.md +50 -1
  75. package/runtime/bigint.gr +410 -517
  76. package/runtime/bigint.md +71 -57
  77. package/runtime/compare.gr +176 -85
  78. package/runtime/compare.md +31 -1
  79. package/runtime/dataStructures.gr +144 -32
  80. package/runtime/dataStructures.md +267 -31
  81. package/runtime/debugPrint.gr +34 -15
  82. package/runtime/debugPrint.md +37 -5
  83. package/runtime/equal.gr +53 -52
  84. package/runtime/equal.md +30 -1
  85. package/runtime/exception.gr +38 -47
  86. package/runtime/exception.md +10 -8
  87. package/runtime/gc.gr +23 -152
  88. package/runtime/gc.md +13 -17
  89. package/runtime/malloc.gr +31 -31
  90. package/runtime/malloc.md +11 -3
  91. package/runtime/numberUtils.gr +193 -174
  92. package/runtime/numberUtils.md +29 -9
  93. package/runtime/numbers.gr +1695 -1021
  94. package/runtime/numbers.md +1098 -134
  95. package/runtime/string.gr +543 -245
  96. package/runtime/string.md +76 -6
  97. package/runtime/unsafe/constants.gr +30 -13
  98. package/runtime/unsafe/constants.md +80 -0
  99. package/runtime/unsafe/conv.gr +55 -28
  100. package/runtime/unsafe/conv.md +41 -9
  101. package/runtime/unsafe/memory.gr +10 -30
  102. package/runtime/unsafe/memory.md +15 -19
  103. package/runtime/unsafe/tags.gr +37 -21
  104. package/runtime/unsafe/tags.md +88 -8
  105. package/runtime/unsafe/wasmf32.gr +30 -36
  106. package/runtime/unsafe/wasmf32.md +64 -56
  107. package/runtime/unsafe/wasmf64.gr +30 -36
  108. package/runtime/unsafe/wasmf64.md +64 -56
  109. package/runtime/unsafe/wasmi32.gr +49 -66
  110. package/runtime/unsafe/wasmi32.md +102 -94
  111. package/runtime/unsafe/wasmi64.gr +52 -79
  112. package/runtime/unsafe/wasmi64.md +108 -100
  113. package/runtime/utils/printing.gr +13 -15
  114. package/runtime/utils/printing.md +11 -3
  115. package/runtime/wasi.gr +294 -295
  116. package/runtime/wasi.md +62 -42
  117. package/set.gr +574 -64
  118. package/set.md +634 -54
  119. package/stack.gr +181 -64
  120. package/stack.md +271 -42
  121. package/string.gr +453 -533
  122. package/string.md +241 -151
  123. package/uint16.gr +369 -0
  124. package/uint16.md +585 -0
  125. package/uint32.gr +470 -0
  126. package/uint32.md +737 -0
  127. package/uint64.gr +471 -0
  128. package/uint64.md +737 -0
  129. package/uint8.gr +369 -0
  130. package/uint8.md +585 -0
  131. package/uri.gr +1093 -0
  132. package/uri.md +477 -0
  133. package/{sys → wasi}/file.gr +914 -500
  134. package/{sys → wasi}/file.md +454 -50
  135. package/wasi/process.gr +292 -0
  136. package/{sys → wasi}/process.md +164 -6
  137. package/wasi/random.gr +77 -0
  138. package/wasi/random.md +80 -0
  139. package/{sys → wasi}/time.gr +15 -22
  140. package/{sys → wasi}/time.md +5 -5
  141. package/immutablearray.gr +0 -929
  142. package/immutablearray.md +0 -1038
  143. package/immutablemap.gr +0 -493
  144. package/immutablemap.md +0 -479
  145. package/immutablepriorityqueue.gr +0 -360
  146. package/immutablepriorityqueue.md +0 -291
  147. package/immutableset.gr +0 -498
  148. package/immutableset.md +0 -449
  149. package/runtime/debug.gr +0 -2
  150. package/runtime/debug.md +0 -6
  151. package/runtime/unsafe/errors.gr +0 -36
  152. package/runtime/unsafe/errors.md +0 -204
  153. package/sys/process.gr +0 -254
  154. package/sys/random.gr +0 -79
  155. package/sys/random.md +0 -66
package/bigint.gr CHANGED
@@ -1,45 +1,28 @@
1
1
  /**
2
- * @module BigInt: Utilities for working with the BigInt type.
3
- * @example import BigInt from "bigint"
2
+ * Utilities for working with the BigInt type.
3
+ *
4
+ * @example from "bigint" include Bigint
5
+ *
6
+ * @example 9223372036854775809t
7
+ * @example 0t
8
+ * @example -9223372036854775809t
4
9
  *
5
10
  * @since v0.5.0
6
11
  */
7
- import WasmI32 from "runtime/unsafe/wasmi32"
8
- import Memory from "runtime/unsafe/memory"
9
- import BI from "runtime/bigint"
10
- import DS from "runtime/dataStructures"
12
+ module BigInt
13
+
14
+ from "runtime/unsafe/wasmi32" include WasmI32
15
+ from "runtime/unsafe/memory" include Memory
16
+ from "runtime/bigint" include Bigint as BI
17
+ from "runtime/dataStructures" include DataStructures as DS
11
18
 
12
- import {
19
+ from "runtime/numbers" include Numbers
20
+ use Numbers.{
13
21
  coerceNumberToBigInt as fromNumber,
14
22
  coerceBigIntToNumber as toNumber,
15
- } from "runtime/numbers"
16
-
17
- /**
18
- * @section Conversions: Functions for converting between Numbers and the BigInt type.
19
- */
20
-
21
- /**
22
- * Converts a Number to a BigInt.
23
- *
24
- * @param number: The value to convert
25
- * @returns The Number represented as a BigInt
26
- *
27
- * @since v0.5.0
28
- */
29
- export fromNumber
30
- /**
31
- * Converts a BigInt to a Number.
32
- *
33
- * @param num: The value to convert
34
- * @returns The BigInt represented as a Number
35
- *
36
- * @since v0.5.0
37
- */
38
- export toNumber
23
+ }
39
24
 
40
- /**
41
- * @section Operations: Mathematical operations for BigInt values.
42
- */
25
+ provide { fromNumber, toNumber }
43
26
 
44
27
  /**
45
28
  * Increments the value by one.
@@ -47,10 +30,13 @@ export toNumber
47
30
  * @param num: The value to increment
48
31
  * @returns The incremented value
49
32
  *
33
+ * @example BigInt.incr(1t) == 2t
34
+ * @example BigInt.incr(-2t) == -1t
35
+ *
50
36
  * @since v0.5.0
51
37
  */
52
38
  @unsafe
53
- export let incr = (num: BigInt) => {
39
+ provide let incr = (num: BigInt) => {
54
40
  WasmI32.toGrain(BI.incr(WasmI32.fromGrain(num))): BigInt
55
41
  }
56
42
 
@@ -60,10 +46,13 @@ export let incr = (num: BigInt) => {
60
46
  * @param num: The value to decrement
61
47
  * @returns The decremented value
62
48
  *
49
+ * @example BigInt.decr(2t) == 1t
50
+ * @example BigInt.decr(-2t) == -3t
51
+ *
63
52
  * @since v0.5.0
64
53
  */
65
54
  @unsafe
66
- export let decr = (num: BigInt) => {
55
+ provide let decr = (num: BigInt) => {
67
56
  WasmI32.toGrain(BI.decr(WasmI32.fromGrain(num))): BigInt
68
57
  }
69
58
 
@@ -73,10 +62,13 @@ export let decr = (num: BigInt) => {
73
62
  * @param num: The operand
74
63
  * @returns The negated operand
75
64
  *
65
+ * @example BigInt.neg(1t) == -1t
66
+ * @example BigInt.neg(-1t) == 1t
67
+ *
76
68
  * @since v0.5.0
77
69
  */
78
70
  @unsafe
79
- export let neg = (num: BigInt) => {
71
+ provide let neg = (num: BigInt) => {
80
72
  WasmI32.toGrain(BI.negate(WasmI32.fromGrain(num))): BigInt
81
73
  }
82
74
 
@@ -86,10 +78,13 @@ export let neg = (num: BigInt) => {
86
78
  * @param num: The operand
87
79
  * @returns The operand's absolute value
88
80
  *
81
+ * @example BigInt.abs(1t) == 1t
82
+ * @example BigInt.abs(-1t) == 1t
83
+ *
89
84
  * @since v0.5.0
90
85
  */
91
86
  @unsafe
92
- export let abs = (num: BigInt) => {
87
+ provide let abs = (num: BigInt) => {
93
88
  WasmI32.toGrain(BI.abs(WasmI32.fromGrain(num))): BigInt
94
89
  }
95
90
 
@@ -100,13 +95,17 @@ export let abs = (num: BigInt) => {
100
95
  * @param num2: The second operand
101
96
  * @returns The sum of the two operands
102
97
  *
103
- * @since v0.5.0
98
+ * @example
99
+ * use BigInt.{ (+) }
100
+ * assert 1t + 1t == 2t
101
+ *
102
+ * @since v0.6.0
103
+ * @history v0.5.0: Originally named `add`
104
104
  */
105
105
  @unsafe
106
- export let add = (num1: BigInt, num2: BigInt) => {
107
- WasmI32.toGrain(
108
- BI.add(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
109
- ): BigInt
106
+ provide let (+) = (num1: BigInt, num2: BigInt) => {
107
+ WasmI32.toGrain(BI.add(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))):
108
+ BigInt
110
109
  }
111
110
 
112
111
  /**
@@ -116,13 +115,17 @@ export let add = (num1: BigInt, num2: BigInt) => {
116
115
  * @param num2: The second operand
117
116
  * @returns The difference of the two operands
118
117
  *
119
- * @since v0.5.0
118
+ * @example
119
+ * use BigInt.{ (-) }
120
+ * assert 3t - 1t == 2t
121
+ *
122
+ * @since v0.6.0
123
+ * @history v0.5.0: Originally named `sub`
120
124
  */
121
125
  @unsafe
122
- export let sub = (num1: BigInt, num2: BigInt) => {
123
- WasmI32.toGrain(
124
- BI.sub(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
125
- ): BigInt
126
+ provide let (-) = (num1: BigInt, num2: BigInt) => {
127
+ WasmI32.toGrain(BI.sub(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))):
128
+ BigInt
126
129
  }
127
130
 
128
131
  /**
@@ -132,13 +135,17 @@ export let sub = (num1: BigInt, num2: BigInt) => {
132
135
  * @param num2: The second operand
133
136
  * @returns The product of the two operands
134
137
  *
135
- * @since v0.5.0
138
+ * @example
139
+ * use BigInt.{ (*) }
140
+ * assert 3t * 3t == 9t
141
+ *
142
+ * @since v0.6.0
143
+ * @history v0.5.0: Originally named `mul`
136
144
  */
137
145
  @unsafe
138
- export let mul = (num1: BigInt, num2: BigInt) => {
139
- WasmI32.toGrain(
140
- BI.mul(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
141
- ): BigInt
146
+ provide let (*) = (num1: BigInt, num2: BigInt) => {
147
+ WasmI32.toGrain(BI.mul(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))):
148
+ BigInt
142
149
  }
143
150
 
144
151
  // For further reading on Truncated vs. Floored division: https://en.wikipedia.org/wiki/Modulo_operation
@@ -151,13 +158,17 @@ export let mul = (num1: BigInt, num2: BigInt) => {
151
158
  * @param num2: The second operand
152
159
  * @returns The quotient of its operands
153
160
  *
154
- * @since v0.5.0
161
+ * @example
162
+ * use BigInt.{ (/) }
163
+ * assert 9t / 3t == 3t
164
+ *
165
+ * @since v0.6.0
166
+ * @history v0.5.0: Originally named `div`
155
167
  */
156
168
  @unsafe
157
- export let div = (num1: BigInt, num2: BigInt) => {
158
- WasmI32.toGrain(
159
- BI.quot(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
160
- ): BigInt
169
+ provide let (/) = (num1: BigInt, num2: BigInt) => {
170
+ WasmI32.toGrain(BI.quot(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))):
171
+ BigInt
161
172
  }
162
173
 
163
174
  /**
@@ -168,13 +179,14 @@ export let div = (num1: BigInt, num2: BigInt) => {
168
179
  * @param num2: The second operand
169
180
  * @returns The remainder of its operands
170
181
  *
182
+ * @example BigInt.rem(3t, 2t) == 1t
183
+ *
171
184
  * @since v0.5.0
172
185
  */
173
186
  @unsafe
174
- export let rem = (num1: BigInt, num2: BigInt) => {
175
- WasmI32.toGrain(
176
- BI.rem(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
177
- ): BigInt
187
+ provide let rem = (num1: BigInt, num2: BigInt) => {
188
+ WasmI32.toGrain(BI.rem(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))):
189
+ BigInt
178
190
  }
179
191
 
180
192
  /**
@@ -184,10 +196,12 @@ export let rem = (num1: BigInt, num2: BigInt) => {
184
196
  * @param num2: The second operand
185
197
  * @returns The quotient and remainder of its operands
186
198
  *
199
+ * @example BigInt.quotRem(7t, 2t) == (3t, 1t))
200
+ *
187
201
  * @since v0.5.0
188
202
  */
189
203
  @unsafe
190
- export let quotRem = (num1: BigInt, num2: BigInt) => {
204
+ provide let quotRem = (num1: BigInt, num2: BigInt) => {
191
205
  let dest = Memory.malloc(8n)
192
206
  BI.quotRem(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2), dest)
193
207
  let q = WasmI32.toGrain(WasmI32.load(dest, 0n)): BigInt
@@ -203,19 +217,16 @@ export let quotRem = (num1: BigInt, num2: BigInt) => {
203
217
  * @param num2: The second operand
204
218
  * @returns The greatest common divisor of its operands
205
219
  *
220
+ * @example BigInt.gcd(36t, 24t) == 12t
221
+ *
206
222
  * @since v0.5.0
207
223
  */
208
224
  @unsafe
209
- export let gcd = (num1: BigInt, num2: BigInt) => {
210
- WasmI32.toGrain(
211
- BI.gcd(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
212
- ): BigInt
225
+ provide let gcd = (num1: BigInt, num2: BigInt) => {
226
+ WasmI32.toGrain(BI.gcd(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))):
227
+ BigInt
213
228
  }
214
229
 
215
- /**
216
- * @section Bitwise operations: Functions for operating on bits of BigInt values.
217
- */
218
-
219
230
  /**
220
231
  * Shifts the bits of the value left by the given number of bits.
221
232
  *
@@ -223,12 +234,17 @@ export let gcd = (num1: BigInt, num2: BigInt) => {
223
234
  * @param places: The number of bits to shift by
224
235
  * @returns The shifted value
225
236
  *
226
- * @since v0.5.0
237
+ * @example
238
+ * use BigInt.{ (<<) }
239
+ * assert (10t << 2l) == 40t
240
+ *
241
+ * @since v0.6.0
242
+ * @history v0.5.0: Originally named `shl`
227
243
  */
228
244
  @unsafe
229
- export let shl = (num: BigInt, places: Int32) => {
245
+ provide let (<<) = (num: BigInt, places: Int32) => {
230
246
  let num = WasmI32.fromGrain(num)
231
- let places = WasmI32.load(WasmI32.fromGrain(places), 8n)
247
+ let places = WasmI32.load(WasmI32.fromGrain(places), 4n)
232
248
  WasmI32.toGrain(BI.shl(num, places)): BigInt
233
249
  }
234
250
 
@@ -239,31 +255,36 @@ export let shl = (num: BigInt, places: Int32) => {
239
255
  * @param places: The amount to shift by
240
256
  * @returns The shifted value
241
257
  *
242
- * @since v0.5.0
258
+ * @example
259
+ * use BigInt.{ (>>) }
260
+ * assert (9999t >> 2l) == 2499t
261
+ *
262
+ * @since v0.6.0
263
+ * @history v0.5.0: Originally named `shr`
243
264
  */
244
265
  @unsafe
245
- export let shr = (num: BigInt, places: Int32) => {
266
+ provide let (>>) = (num: BigInt, places: Int32) => {
246
267
  let num = WasmI32.fromGrain(num)
247
- let places = WasmI32.load(WasmI32.fromGrain(places), 8n)
268
+ let places = WasmI32.load(WasmI32.fromGrain(places), 4n)
248
269
  WasmI32.toGrain(BI.shrS(num, places)): BigInt
249
270
  }
250
271
 
251
- /**
252
- * @section Comparisons: Functions for comparing BigInt values.
253
- */
254
-
255
272
  /**
256
273
  * Checks if the given value is equal to zero.
257
274
  *
258
275
  * @param num: The value to inspect
259
276
  * @returns `true` if the first value is equal to zero or `false` otherwise
260
277
  *
278
+ * @example assert BigInt.eqz(0t) == true
279
+ * @example assert BigInt.eqz(1t) == false
280
+ *
261
281
  * @since v0.5.0
262
282
  */
263
283
  @unsafe
264
- export let eqz = (num: BigInt) => {
265
- let num = WasmI32.fromGrain(num)
266
- BI.eqz(num)
284
+ provide let eqz = (num: BigInt) => {
285
+ let result = BI.eqz(WasmI32.fromGrain(num))
286
+ ignore(num)
287
+ result
267
288
  }
268
289
 
269
290
  /**
@@ -273,13 +294,22 @@ export let eqz = (num: BigInt) => {
273
294
  * @param num2: The second value
274
295
  * @returns `true` if the first value is equal to the second value or `false` otherwise
275
296
  *
276
- * @since v0.5.0
297
+ * @example
298
+ * use BigInt.{ (==) }
299
+ * assert 1t == 1t
300
+ * @example
301
+ * use BigInt.{ (==) }
302
+ * assert -10t == -10t
303
+ *
304
+ * @since v0.6.0
305
+ * @history v0.5.0: Originally named `eq`
277
306
  */
278
307
  @unsafe
279
- export let eq = (num1: BigInt, num2: BigInt) => {
280
- let num1 = WasmI32.fromGrain(num1)
281
- let num2 = WasmI32.fromGrain(num2)
282
- BI.eq(num1, num2)
308
+ provide let (==) = (num1: BigInt, num2: BigInt) => {
309
+ let result = BI.eq(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
310
+ ignore(num1)
311
+ ignore(num2)
312
+ result
283
313
  }
284
314
 
285
315
  /**
@@ -289,13 +319,22 @@ export let eq = (num1: BigInt, num2: BigInt) => {
289
319
  * @param num2: The second value
290
320
  * @returns `true` if the first value is not equal to the second value or `false` otherwise
291
321
  *
292
- * @since v0.5.0
322
+ * @example
323
+ * use BigInt.{ (!=) }
324
+ * assert 1t != 2t
325
+ * @example
326
+ * use BigInt.{ (!=) }
327
+ * assert -10t != -20t
328
+ *
329
+ * @since v0.6.0
330
+ * @history v0.5.0: Originally named `ne`
293
331
  */
294
332
  @unsafe
295
- export let ne = (num1: BigInt, num2: BigInt) => {
296
- let num1 = WasmI32.fromGrain(num1)
297
- let num2 = WasmI32.fromGrain(num2)
298
- BI.ne(num1, num2)
333
+ provide let (!=) = (num1: BigInt, num2: BigInt) => {
334
+ let result = BI.ne(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
335
+ ignore(num1)
336
+ ignore(num2)
337
+ result
299
338
  }
300
339
 
301
340
  /**
@@ -305,13 +344,22 @@ export let ne = (num1: BigInt, num2: BigInt) => {
305
344
  * @param num2: The second value
306
345
  * @returns `true` if the first value is less than the second value or `false` otherwise
307
346
  *
308
- * @since v0.5.0
347
+ * @example
348
+ * use BigInt.{ (<) }
349
+ * assert 1t < 2t
350
+ * @example
351
+ * use BigInt.{ (<) }
352
+ * assert -10t < 0t
353
+ *
354
+ * @since v0.6.0
355
+ * @history v0.5.0: Originally named `lt`
309
356
  */
310
357
  @unsafe
311
- export let lt = (num1: BigInt, num2: BigInt) => {
312
- let num1 = WasmI32.fromGrain(num1)
313
- let num2 = WasmI32.fromGrain(num2)
314
- BI.lt(num1, num2)
358
+ provide let (<) = (num1: BigInt, num2: BigInt) => {
359
+ let result = BI.lt(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
360
+ ignore(num1)
361
+ ignore(num2)
362
+ result
315
363
  }
316
364
 
317
365
  /**
@@ -321,13 +369,25 @@ export let lt = (num1: BigInt, num2: BigInt) => {
321
369
  * @param num2: The second value
322
370
  * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
323
371
  *
324
- * @since v0.5.0
372
+ * @example
373
+ * use BigInt.{ (<=) }
374
+ * assert 1t <= 1t
375
+ * @example
376
+ * use BigInt.{ (<=) }
377
+ * assert -10t <= 0t
378
+ * @example
379
+ * use BigInt.{ (<=) }
380
+ * assert 2t <= 3t
381
+ *
382
+ * @since v0.6.0
383
+ * @history v0.5.0: Originally named `lte`
325
384
  */
326
385
  @unsafe
327
- export let lte = (num1: BigInt, num2: BigInt) => {
328
- let num1 = WasmI32.fromGrain(num1)
329
- let num2 = WasmI32.fromGrain(num2)
330
- BI.lte(num1, num2)
386
+ provide let (<=) = (num1: BigInt, num2: BigInt) => {
387
+ let result = BI.lte(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
388
+ ignore(num1)
389
+ ignore(num2)
390
+ result
331
391
  }
332
392
 
333
393
  /**
@@ -337,13 +397,22 @@ export let lte = (num1: BigInt, num2: BigInt) => {
337
397
  * @param num2: The second value
338
398
  * @returns `true` if the first value is greater than the second value or `false` otherwise
339
399
  *
340
- * @since v0.5.0
400
+ * @example
401
+ * use BigInt.{ (>) }
402
+ * assert 2t > 1t
403
+ * @example
404
+ * use BigInt.{ (>) }
405
+ * assert 0t > -10t
406
+ *
407
+ * @since v0.6.0
408
+ * @history v0.5.0: Originally named `gt`
341
409
  */
342
410
  @unsafe
343
- export let gt = (num1: BigInt, num2: BigInt) => {
344
- let num1 = WasmI32.fromGrain(num1)
345
- let num2 = WasmI32.fromGrain(num2)
346
- BI.gt(num1, num2)
411
+ provide let (>) = (num1: BigInt, num2: BigInt) => {
412
+ let result = BI.gt(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
413
+ ignore(num1)
414
+ ignore(num2)
415
+ result
347
416
  }
348
417
 
349
418
  /**
@@ -353,29 +422,39 @@ export let gt = (num1: BigInt, num2: BigInt) => {
353
422
  * @param num2: The second value
354
423
  * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
355
424
  *
356
- * @since v0.5.0
425
+ * @example
426
+ * use BigInt.{ (>=) }
427
+ * assert 1t >= 1t
428
+ * @example
429
+ * use BigInt.{ (>=) }
430
+ * assert 0t >= -10t
431
+ * @example
432
+ * use BigInt.{ (>=) }
433
+ * assert 3t >= 2t
434
+ *
435
+ * @since v0.6.0
436
+ * @history v0.5.0: Originally named `gte`
357
437
  */
358
438
  @unsafe
359
- export let gte = (num1: BigInt, num2: BigInt) => {
360
- let num1 = WasmI32.fromGrain(num1)
361
- let num2 = WasmI32.fromGrain(num2)
362
- BI.gte(num1, num2)
439
+ provide let (>=) = (num1: BigInt, num2: BigInt) => {
440
+ let result = BI.gte(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
441
+ ignore(num1)
442
+ ignore(num2)
443
+ result
363
444
  }
364
445
 
365
- /**
366
- * @section Bitwise logic: Boolean operations on the bits of BigInt values.
367
- */
368
-
369
446
  /**
370
447
  * Computes the bitwise NOT of the given value.
371
448
  *
372
449
  * @param num: The given value
373
450
  * @returns Containing the inverted bits of the given value
374
451
  *
452
+ * @example BigInt.lnot(91234t) == -91235t
453
+ *
375
454
  * @since v0.5.0
376
455
  */
377
456
  @unsafe
378
- export let lnot = (num: BigInt) => {
457
+ provide let lnot = (num: BigInt) => {
379
458
  WasmI32.toGrain(BI.bitwiseNot(WasmI32.fromGrain(num))): BigInt
380
459
  }
381
460
 
@@ -386,10 +465,15 @@ export let lnot = (num: BigInt) => {
386
465
  * @param num2: The second operand
387
466
  * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
388
467
  *
389
- * @since v0.5.0
468
+ * @example
469
+ * use BigInt.{ (&) }
470
+ * assert (4t & 3t) == 0t
471
+ *
472
+ * @since v0.6.0
473
+ * @history v0.5.0: Originally named `land`
390
474
  */
391
475
  @unsafe
392
- export let land = (num1: BigInt, num2: BigInt) => {
476
+ provide let (&) = (num1: BigInt, num2: BigInt) => {
393
477
  WasmI32.toGrain(
394
478
  BI.bitwiseAnd(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
395
479
  ): BigInt
@@ -402,10 +486,15 @@ export let land = (num1: BigInt, num2: BigInt) => {
402
486
  * @param num2: The second operand
403
487
  * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
404
488
  *
405
- * @since v0.5.0
489
+ * @example
490
+ * use BigInt.{ (|) }
491
+ * assert (5t | 3t) == 7t
492
+ *
493
+ * @since v0.6.0
494
+ * @history v0.5.0: Originally named `lor`
406
495
  */
407
496
  @unsafe
408
- export let lor = (num1: BigInt, num2: BigInt) => {
497
+ provide let (|) = (num1: BigInt, num2: BigInt) => {
409
498
  WasmI32.toGrain(
410
499
  BI.bitwiseOr(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
411
500
  ): BigInt
@@ -418,10 +507,15 @@ export let lor = (num1: BigInt, num2: BigInt) => {
418
507
  * @param num2: The second operand
419
508
  * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
420
509
  *
421
- * @since v0.5.0
510
+ * @example
511
+ * use BigInt.{ (^) }
512
+ * assert (5t ^ 3t) == 6t
513
+ *
514
+ * @since v0.6.0
515
+ * @history v0.5.0: Originally named `lxor`
422
516
  */
423
517
  @unsafe
424
- export let lxor = (num1: BigInt, num2: BigInt) => {
518
+ provide let (^) = (num1: BigInt, num2: BigInt) => {
425
519
  WasmI32.toGrain(
426
520
  BI.bitwiseXor(WasmI32.fromGrain(num1), WasmI32.fromGrain(num2))
427
521
  ): BigInt
@@ -434,13 +528,14 @@ export let lxor = (num1: BigInt, num2: BigInt) => {
434
528
  * @param num: The value to inspect
435
529
  * @returns The amount of leading zeros
436
530
  *
531
+ * @example BigInt.clz(5t) == 2147483647t
532
+ *
437
533
  * @since v0.5.0
438
534
  */
439
535
  @unsafe
440
- export let clz = (num: BigInt) => {
441
- WasmI32.toGrain(
442
- DS.newInt32(BI.countLeadingZeros(WasmI32.fromGrain(num)))
443
- ): Int32
536
+ provide let clz = (num: BigInt) => {
537
+ WasmI32.toGrain(DS.newInt32(BI.countLeadingZeros(WasmI32.fromGrain(num)))):
538
+ Int32
444
539
  }
445
540
 
446
541
  /**
@@ -449,13 +544,14 @@ export let clz = (num: BigInt) => {
449
544
  * @param num: The value to inspect
450
545
  * @returns The amount of trailing zeros
451
546
  *
547
+ * @example BigInt.ctz(14t) == 1t
548
+ *
452
549
  * @since v0.5.0
453
550
  */
454
551
  @unsafe
455
- export let ctz = (num: BigInt) => {
456
- WasmI32.toGrain(
457
- DS.newInt64(BI.countTrailingZeros(WasmI32.fromGrain(num)))
458
- ): Int64
552
+ provide let ctz = (num: BigInt) => {
553
+ WasmI32.toGrain(DS.newInt64(BI.countTrailingZeros(WasmI32.fromGrain(num)))):
554
+ Int64
459
555
  }
460
556
 
461
557
  /**
@@ -465,10 +561,12 @@ export let ctz = (num: BigInt) => {
465
561
  * @param num: The value to inspect
466
562
  * @returns The amount of 1-bits in its operand
467
563
  *
564
+ * @example BigInt.popcnt(14t) == 1t
565
+ *
468
566
  * @since v0.5.0
469
567
  */
470
568
  @unsafe
471
- export let popcnt = (num: BigInt) => {
569
+ provide let popcnt = (num: BigInt) => {
472
570
  let flagDest = Memory.malloc(4n)
473
571
  WasmI32.store(flagDest, 0n, 0n)
474
572
  let res = BI.popcnt(WasmI32.fromGrain(num), flagDest)
@@ -479,19 +577,20 @@ export let popcnt = (num: BigInt) => {
479
577
  }
480
578
  }
481
579
 
482
- /**
483
- * @section Other: Other functions on BigInts.
484
- */
485
-
486
580
  /**
487
581
  * Converts the given operand to a string.
488
582
  *
489
583
  * @param num: The operand
490
584
  * @returns The operand, as a string
491
585
  *
586
+ * @example BigInt.toString(1t) == "1"
587
+ * @example BigInt.toString(-1t) == "-1"
588
+ *
492
589
  * @since v0.5.0
493
590
  */
494
591
  @unsafe
495
- export let toString = (num: BigInt) => {
496
- BI.bigIntToString10(WasmI32.fromGrain(num))
592
+ provide let toString = (num: BigInt) => {
593
+ let string = BI.bigIntToString10(WasmI32.fromGrain(num))
594
+ ignore(num)
595
+ string
497
596
  }