@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.
- package/CHANGELOG.md +201 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +62 -40
- package/hash.md +27 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2071 -0
- package/json.md +646 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +193 -174
- package/runtime/numberUtils.md +29 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +543 -245
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/int64.gr
CHANGED
|
@@ -1,47 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
2
|
+
* Utilities for working with the Int64 type.
|
|
3
|
+
*
|
|
4
|
+
* @example from "int64" include Int64
|
|
4
5
|
*
|
|
5
6
|
* @since v0.2.0
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
module Int64
|
|
9
|
+
|
|
10
|
+
from "runtime/unsafe/wasmi32" include WasmI32
|
|
11
|
+
from "runtime/unsafe/wasmi64" include WasmI64
|
|
12
|
+
use WasmI64.{ (==), (!=), (&), (|), (^), (<<), (>>), (<), (<=), (>), (>=) }
|
|
13
|
+
from "runtime/exception" include Exception
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
from "runtime/dataStructures" include DataStructures
|
|
16
|
+
use DataStructures.{ newInt64 }
|
|
12
17
|
|
|
13
|
-
|
|
18
|
+
from "runtime/numbers" include Numbers
|
|
19
|
+
use Numbers.{
|
|
14
20
|
coerceNumberToInt64 as fromNumber,
|
|
15
21
|
coerceInt64ToNumber as toNumber,
|
|
16
|
-
}
|
|
22
|
+
}
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
* @section Conversions: Functions for converting between Numbers and the Int64 type.
|
|
20
|
-
*/
|
|
24
|
+
provide { fromNumber, toNumber }
|
|
21
25
|
|
|
22
26
|
/**
|
|
23
|
-
* Converts a
|
|
27
|
+
* Converts a Uint64 to an Int64.
|
|
24
28
|
*
|
|
25
29
|
* @param number: The value to convert
|
|
26
|
-
* @returns The
|
|
27
|
-
*
|
|
28
|
-
* @since v0.2.0
|
|
29
|
-
*/
|
|
30
|
-
export fromNumber
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Converts an Int64 to a Number.
|
|
34
|
-
*
|
|
35
|
-
* @param value: The value to convert
|
|
36
|
-
* @returns The Int64 represented as a Number
|
|
30
|
+
* @returns The Uint64 represented as an Int64
|
|
37
31
|
*
|
|
38
|
-
* @since v0.
|
|
39
|
-
*/
|
|
40
|
-
export toNumber
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @section Operations: Mathematical operations for Int64 values.
|
|
32
|
+
* @since v0.6.0
|
|
44
33
|
*/
|
|
34
|
+
@unsafe
|
|
35
|
+
provide let fromUint64 = (number: Uint64) => {
|
|
36
|
+
let x = WasmI64.load(WasmI32.fromGrain(number), 8n)
|
|
37
|
+
let result = newInt64(x)
|
|
38
|
+
WasmI32.toGrain(result): Int64
|
|
39
|
+
}
|
|
45
40
|
|
|
46
41
|
/**
|
|
47
42
|
* Increments the value by one.
|
|
@@ -52,9 +47,10 @@ export toNumber
|
|
|
52
47
|
* @since v0.2.0
|
|
53
48
|
*/
|
|
54
49
|
@unsafe
|
|
55
|
-
|
|
50
|
+
provide let incr = (value: Int64) => {
|
|
51
|
+
use WasmI64.{ (+) }
|
|
56
52
|
let value = WasmI32.fromGrain(value)
|
|
57
|
-
let ptr = newInt64(WasmI64.
|
|
53
|
+
let ptr = newInt64(WasmI64.load(value, 8n) + 1N)
|
|
58
54
|
WasmI32.toGrain(ptr): Int64
|
|
59
55
|
}
|
|
60
56
|
|
|
@@ -67,9 +63,10 @@ export let incr = (value: Int64) => {
|
|
|
67
63
|
* @since v0.2.0
|
|
68
64
|
*/
|
|
69
65
|
@unsafe
|
|
70
|
-
|
|
66
|
+
provide let decr = (value: Int64) => {
|
|
67
|
+
use WasmI64.{ (-) }
|
|
71
68
|
let value = WasmI32.fromGrain(value)
|
|
72
|
-
let ptr = newInt64(WasmI64.
|
|
69
|
+
let ptr = newInt64(WasmI64.load(value, 8n) - 1N)
|
|
73
70
|
WasmI32.toGrain(ptr): Int64
|
|
74
71
|
}
|
|
75
72
|
|
|
@@ -80,13 +77,15 @@ export let decr = (value: Int64) => {
|
|
|
80
77
|
* @param y: The second operand
|
|
81
78
|
* @returns The sum of the two operands
|
|
82
79
|
*
|
|
83
|
-
* @since v0.
|
|
80
|
+
* @since v0.6.0
|
|
81
|
+
* @history v0.2.0: Originally named `add`
|
|
84
82
|
*/
|
|
85
83
|
@unsafe
|
|
86
|
-
|
|
84
|
+
provide let (+) = (x: Int64, y: Int64) => {
|
|
85
|
+
use WasmI64.{ (+) }
|
|
87
86
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
88
87
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
89
|
-
let ptr = newInt64(
|
|
88
|
+
let ptr = newInt64(xv + yv)
|
|
90
89
|
WasmI32.toGrain(ptr): Int64
|
|
91
90
|
}
|
|
92
91
|
|
|
@@ -97,13 +96,15 @@ export let add = (x: Int64, y: Int64) => {
|
|
|
97
96
|
* @param y: The second operand
|
|
98
97
|
* @returns The difference of the two operands
|
|
99
98
|
*
|
|
100
|
-
* @since v0.
|
|
99
|
+
* @since v0.6.0
|
|
100
|
+
* @history v0.2.0: Originally named `sub`
|
|
101
101
|
*/
|
|
102
102
|
@unsafe
|
|
103
|
-
|
|
103
|
+
provide let (-) = (x: Int64, y: Int64) => {
|
|
104
|
+
use WasmI64.{ (-) }
|
|
104
105
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
105
106
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
106
|
-
let ptr = newInt64(
|
|
107
|
+
let ptr = newInt64(xv - yv)
|
|
107
108
|
WasmI32.toGrain(ptr): Int64
|
|
108
109
|
}
|
|
109
110
|
|
|
@@ -114,13 +115,15 @@ export let sub = (x: Int64, y: Int64) => {
|
|
|
114
115
|
* @param y: The second operand
|
|
115
116
|
* @returns The product of the two operands
|
|
116
117
|
*
|
|
117
|
-
* @since v0.
|
|
118
|
+
* @since v0.6.0
|
|
119
|
+
* @history v0.2.0: Originally named `*`
|
|
118
120
|
*/
|
|
119
121
|
@unsafe
|
|
120
|
-
|
|
122
|
+
provide let (*) = (x: Int64, y: Int64) => {
|
|
123
|
+
use WasmI64.{ (*) }
|
|
121
124
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
122
125
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
123
|
-
let ptr = newInt64(
|
|
126
|
+
let ptr = newInt64(xv * yv)
|
|
124
127
|
WasmI32.toGrain(ptr): Int64
|
|
125
128
|
}
|
|
126
129
|
|
|
@@ -131,30 +134,15 @@ export let mul = (x: Int64, y: Int64) => {
|
|
|
131
134
|
* @param y: The second operand
|
|
132
135
|
* @returns The quotient of its operands
|
|
133
136
|
*
|
|
134
|
-
* @since v0.
|
|
135
|
-
|
|
136
|
-
@unsafe
|
|
137
|
-
export let div = (x: Int64, y: Int64) => {
|
|
138
|
-
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
139
|
-
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
140
|
-
let ptr = newInt64(WasmI64.divS(xv, yv))
|
|
141
|
-
WasmI32.toGrain(ptr): Int64
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Computes the quotient of its operands using unsigned division.
|
|
146
|
-
*
|
|
147
|
-
* @param x: The first operand
|
|
148
|
-
* @param y: The second operand
|
|
149
|
-
* @returns The quotient of its operands
|
|
150
|
-
*
|
|
151
|
-
* @since v0.2.0
|
|
137
|
+
* @since v0.6.0
|
|
138
|
+
* @history v0.2.0: Originally named `div`
|
|
152
139
|
*/
|
|
153
140
|
@unsafe
|
|
154
|
-
|
|
141
|
+
provide let (/) = (x: Int64, y: Int64) => {
|
|
142
|
+
use WasmI64.{ (/) }
|
|
155
143
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
156
144
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
157
|
-
let ptr = newInt64(
|
|
145
|
+
let ptr = newInt64(xv / yv)
|
|
158
146
|
WasmI32.toGrain(ptr): Int64
|
|
159
147
|
}
|
|
160
148
|
|
|
@@ -168,34 +156,18 @@ export let divU = (x: Int64, y: Int64) => {
|
|
|
168
156
|
* @since v0.2.0
|
|
169
157
|
*/
|
|
170
158
|
@unsafe
|
|
171
|
-
|
|
159
|
+
provide let rem = (x: Int64, y: Int64) => {
|
|
172
160
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
173
161
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
174
162
|
let ptr = newInt64(WasmI64.remS(xv, yv))
|
|
175
163
|
WasmI32.toGrain(ptr): Int64
|
|
176
164
|
}
|
|
177
165
|
|
|
178
|
-
/**
|
|
179
|
-
* Computes the remainder of the division of its operands using unsigned division.
|
|
180
|
-
*
|
|
181
|
-
* @param x: The first operand
|
|
182
|
-
* @param y: The second operand
|
|
183
|
-
* @returns The remainder of its operands
|
|
184
|
-
*
|
|
185
|
-
* @since v0.2.0
|
|
186
|
-
*/
|
|
187
|
-
@unsafe
|
|
188
|
-
export let remU = (x: Int64, y: Int64) => {
|
|
189
|
-
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
190
|
-
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
191
|
-
let ptr = newInt64(WasmI64.remU(xv, yv))
|
|
192
|
-
WasmI32.toGrain(ptr): Int64
|
|
193
|
-
}
|
|
194
|
-
|
|
195
166
|
@unsafe
|
|
196
167
|
let abs = n => {
|
|
197
|
-
|
|
198
|
-
|
|
168
|
+
use WasmI64.{ (-) }
|
|
169
|
+
let mask = n >> 63N
|
|
170
|
+
(n ^ mask) - mask
|
|
199
171
|
}
|
|
200
172
|
|
|
201
173
|
/**
|
|
@@ -208,10 +180,12 @@ let abs = n => {
|
|
|
208
180
|
*
|
|
209
181
|
* @throws ModuloByZero: When `y` is zero
|
|
210
182
|
*
|
|
211
|
-
* @since v0.
|
|
183
|
+
* @since v0.6.0
|
|
184
|
+
* @history v0.2.0: Originally named `mod`
|
|
212
185
|
*/
|
|
213
186
|
@unsafe
|
|
214
|
-
|
|
187
|
+
provide let (%) = (x: Int64, y: Int64) => {
|
|
188
|
+
use WasmI64.{ (-) }
|
|
215
189
|
let xval = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
216
190
|
let yval = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
217
191
|
|
|
@@ -219,26 +193,18 @@ export let mod = (x: Int64, y: Int64) => {
|
|
|
219
193
|
throw Exception.ModuloByZero
|
|
220
194
|
}
|
|
221
195
|
|
|
222
|
-
let ptr = if (
|
|
196
|
+
let ptr = if ((xval ^ yval) < 0N) {
|
|
223
197
|
let xabs = abs(xval)
|
|
224
198
|
let yabs = abs(yval)
|
|
225
199
|
let mval = WasmI64.remS(xabs, yabs)
|
|
226
|
-
let mres =
|
|
227
|
-
newInt64(
|
|
228
|
-
if (WasmI64.ne(mval, 0N)) (
|
|
229
|
-
if (WasmI64.ltS(yval, 0N)) WasmI64.sub(0N, mres) else mres
|
|
230
|
-
) else 0N
|
|
231
|
-
)
|
|
200
|
+
let mres = yabs - mval
|
|
201
|
+
newInt64(if (mval != 0N) (if (yval < 0N) 0N - mres else mres) else 0N)
|
|
232
202
|
} else {
|
|
233
203
|
newInt64(WasmI64.remS(xval, yval))
|
|
234
204
|
}
|
|
235
205
|
WasmI32.toGrain(ptr): Int64
|
|
236
206
|
}
|
|
237
207
|
|
|
238
|
-
/**
|
|
239
|
-
* @section Bitwise operations: Functions for operating on bits of Int64 values.
|
|
240
|
-
*/
|
|
241
|
-
|
|
242
208
|
/**
|
|
243
209
|
* Rotates the bits of the value left by the given number of bits.
|
|
244
210
|
*
|
|
@@ -249,7 +215,7 @@ export let mod = (x: Int64, y: Int64) => {
|
|
|
249
215
|
* @since v0.4.0
|
|
250
216
|
*/
|
|
251
217
|
@unsafe
|
|
252
|
-
|
|
218
|
+
provide let rotl = (value: Int64, amount: Int64) => {
|
|
253
219
|
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
254
220
|
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
255
221
|
let ptr = newInt64(WasmI64.rotl(xv, yv))
|
|
@@ -266,7 +232,7 @@ export let rotl = (value: Int64, amount: Int64) => {
|
|
|
266
232
|
* @since v0.4.0
|
|
267
233
|
*/
|
|
268
234
|
@unsafe
|
|
269
|
-
|
|
235
|
+
provide let rotr = (value: Int64, amount: Int64) => {
|
|
270
236
|
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
271
237
|
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
272
238
|
let ptr = newInt64(WasmI64.rotr(xv, yv))
|
|
@@ -280,13 +246,14 @@ export let rotr = (value: Int64, amount: Int64) => {
|
|
|
280
246
|
* @param amount: The number of bits to shift by
|
|
281
247
|
* @returns The shifted value
|
|
282
248
|
*
|
|
283
|
-
* @since v0.
|
|
249
|
+
* @since v0.6.0
|
|
250
|
+
* @history v0.2.0: Originally named `shl`
|
|
284
251
|
*/
|
|
285
252
|
@unsafe
|
|
286
|
-
|
|
253
|
+
provide let (<<) = (value: Int64, amount: Int64) => {
|
|
287
254
|
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
288
255
|
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
289
|
-
let ptr = newInt64(
|
|
256
|
+
let ptr = newInt64(xv << yv)
|
|
290
257
|
WasmI32.toGrain(ptr): Int64
|
|
291
258
|
}
|
|
292
259
|
|
|
@@ -297,37 +264,17 @@ export let shl = (value: Int64, amount: Int64) => {
|
|
|
297
264
|
* @param amount: The amount to shift by
|
|
298
265
|
* @returns The shifted value
|
|
299
266
|
*
|
|
300
|
-
* @since v0.
|
|
267
|
+
* @since v0.6.0
|
|
268
|
+
* @history v0.2.0: Originally named `shr`
|
|
301
269
|
*/
|
|
302
270
|
@unsafe
|
|
303
|
-
|
|
271
|
+
provide let (>>) = (value: Int64, amount: Int64) => {
|
|
304
272
|
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
305
273
|
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
306
|
-
let ptr = newInt64(
|
|
274
|
+
let ptr = newInt64(xv >> yv)
|
|
307
275
|
WasmI32.toGrain(ptr): Int64
|
|
308
276
|
}
|
|
309
277
|
|
|
310
|
-
/**
|
|
311
|
-
* Shifts the bits of the value right by the given number of bits.
|
|
312
|
-
*
|
|
313
|
-
* @param value: The value to shift
|
|
314
|
-
* @param amount: The amount to shift by
|
|
315
|
-
* @returns The shifted value
|
|
316
|
-
*
|
|
317
|
-
* @since v0.2.0
|
|
318
|
-
*/
|
|
319
|
-
@unsafe
|
|
320
|
-
export let shrU = (value: Int64, amount: Int64) => {
|
|
321
|
-
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
322
|
-
let yv = WasmI64.load(WasmI32.fromGrain(amount), 8n)
|
|
323
|
-
let ptr = newInt64(WasmI64.shrU(xv, yv))
|
|
324
|
-
WasmI32.toGrain(ptr): Int64
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
/**
|
|
328
|
-
* @section Comparisons: Functions for comparing Int64 values.
|
|
329
|
-
*/
|
|
330
|
-
|
|
331
278
|
/**
|
|
332
279
|
* Checks if the first value is equal to the second value.
|
|
333
280
|
*
|
|
@@ -335,13 +282,14 @@ export let shrU = (value: Int64, amount: Int64) => {
|
|
|
335
282
|
* @param y: The second value
|
|
336
283
|
* @returns `true` if the first value is equal to the second value or `false` otherwise
|
|
337
284
|
*
|
|
338
|
-
* @since v0.
|
|
285
|
+
* @since v0.6.0
|
|
286
|
+
* @history v0.4.0: Originally named `eq`
|
|
339
287
|
*/
|
|
340
288
|
@unsafe
|
|
341
|
-
|
|
289
|
+
provide let (==) = (x: Int64, y: Int64) => {
|
|
342
290
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
343
291
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
344
|
-
|
|
292
|
+
xv == yv
|
|
345
293
|
}
|
|
346
294
|
|
|
347
295
|
/**
|
|
@@ -351,13 +299,14 @@ export let eq = (x: Int64, y: Int64) => {
|
|
|
351
299
|
* @param y: The second value
|
|
352
300
|
* @returns `true` if the first value is not equal to the second value or `false` otherwise
|
|
353
301
|
*
|
|
354
|
-
* @since v0.
|
|
302
|
+
* @since v0.6.0
|
|
303
|
+
* @history v0.4.0: Originally named `ne`
|
|
355
304
|
*/
|
|
356
305
|
@unsafe
|
|
357
|
-
|
|
306
|
+
provide let (!=) = (x: Int64, y: Int64) => {
|
|
358
307
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
359
308
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
360
|
-
|
|
309
|
+
xv != yv
|
|
361
310
|
}
|
|
362
311
|
|
|
363
312
|
/**
|
|
@@ -369,7 +318,7 @@ export let ne = (x: Int64, y: Int64) => {
|
|
|
369
318
|
* @since v0.4.0
|
|
370
319
|
*/
|
|
371
320
|
@unsafe
|
|
372
|
-
|
|
321
|
+
provide let eqz = (value: Int64) => {
|
|
373
322
|
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
374
323
|
WasmI64.eqz(xv)
|
|
375
324
|
}
|
|
@@ -381,29 +330,14 @@ export let eqz = (value: Int64) => {
|
|
|
381
330
|
* @param y: The second value
|
|
382
331
|
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
383
332
|
*
|
|
384
|
-
* @since v0.
|
|
385
|
-
|
|
386
|
-
@unsafe
|
|
387
|
-
export let lt = (x: Int64, y: Int64) => {
|
|
388
|
-
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
389
|
-
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
390
|
-
WasmI64.ltS(xv, yv)
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Checks if the first unsigned value is less than the second unsigned value.
|
|
395
|
-
*
|
|
396
|
-
* @param x: The first value
|
|
397
|
-
* @param y: The second value
|
|
398
|
-
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
399
|
-
*
|
|
400
|
-
* @since v0.5.0
|
|
333
|
+
* @since v0.6.0
|
|
334
|
+
* @history v0.2.0: Originally named `lt`
|
|
401
335
|
*/
|
|
402
336
|
@unsafe
|
|
403
|
-
|
|
337
|
+
provide let (<) = (x: Int64, y: Int64) => {
|
|
404
338
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
405
339
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
406
|
-
|
|
340
|
+
xv < yv
|
|
407
341
|
}
|
|
408
342
|
|
|
409
343
|
/**
|
|
@@ -413,29 +347,14 @@ export let ltU = (x: Int64, y: Int64) => {
|
|
|
413
347
|
* @param y: The second value
|
|
414
348
|
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
415
349
|
*
|
|
416
|
-
* @since v0.
|
|
417
|
-
|
|
418
|
-
@unsafe
|
|
419
|
-
export let gt = (x: Int64, y: Int64) => {
|
|
420
|
-
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
421
|
-
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
422
|
-
WasmI64.gtS(xv, yv)
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* Checks if the first unsigned value is greater than the second unsigned value.
|
|
427
|
-
*
|
|
428
|
-
* @param x: The first value
|
|
429
|
-
* @param y: The second value
|
|
430
|
-
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
431
|
-
*
|
|
432
|
-
* @since v0.5.0
|
|
350
|
+
* @since v0.6.0
|
|
351
|
+
* @history v0.2.0: Originally named `gt`
|
|
433
352
|
*/
|
|
434
353
|
@unsafe
|
|
435
|
-
|
|
354
|
+
provide let (>) = (x: Int64, y: Int64) => {
|
|
436
355
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
437
356
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
438
|
-
|
|
357
|
+
xv > yv
|
|
439
358
|
}
|
|
440
359
|
|
|
441
360
|
/**
|
|
@@ -445,29 +364,14 @@ export let gtU = (x: Int64, y: Int64) => {
|
|
|
445
364
|
* @param y: The second value
|
|
446
365
|
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
447
366
|
*
|
|
448
|
-
* @since v0.
|
|
367
|
+
* @since v0.6.0
|
|
368
|
+
* @history v0.2.0: Originally named `lte`
|
|
449
369
|
*/
|
|
450
370
|
@unsafe
|
|
451
|
-
|
|
371
|
+
provide let (<=) = (x: Int64, y: Int64) => {
|
|
452
372
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
453
373
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
/**
|
|
458
|
-
* Checks if the first unsigned value is less than or equal to the second unsigned value.
|
|
459
|
-
*
|
|
460
|
-
* @param x: The first value
|
|
461
|
-
* @param y: The second value
|
|
462
|
-
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
463
|
-
*
|
|
464
|
-
* @since v0.5.0
|
|
465
|
-
*/
|
|
466
|
-
@unsafe
|
|
467
|
-
export let lteU = (x: Int64, y: Int64) => {
|
|
468
|
-
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
469
|
-
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
470
|
-
WasmI64.leU(xv, yv)
|
|
374
|
+
xv <= yv
|
|
471
375
|
}
|
|
472
376
|
|
|
473
377
|
/**
|
|
@@ -477,35 +381,16 @@ export let lteU = (x: Int64, y: Int64) => {
|
|
|
477
381
|
* @param y: The second value
|
|
478
382
|
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
479
383
|
*
|
|
480
|
-
* @since v0.
|
|
384
|
+
* @since v0.6.0
|
|
385
|
+
* @history v0.2.0: Originally named `gte`
|
|
481
386
|
*/
|
|
482
387
|
@unsafe
|
|
483
|
-
|
|
388
|
+
provide let (>=) = (x: Int64, y: Int64) => {
|
|
484
389
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
485
390
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
486
|
-
|
|
391
|
+
xv >= yv
|
|
487
392
|
}
|
|
488
393
|
|
|
489
|
-
/**
|
|
490
|
-
* Checks if the first unsigned value is greater than or equal to the second unsigned value.
|
|
491
|
-
*
|
|
492
|
-
* @param x: The first value
|
|
493
|
-
* @param y: The second value
|
|
494
|
-
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
495
|
-
*
|
|
496
|
-
* @since v0.5.0
|
|
497
|
-
*/
|
|
498
|
-
@unsafe
|
|
499
|
-
export let gteU = (x: Int64, y: Int64) => {
|
|
500
|
-
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
501
|
-
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
502
|
-
WasmI64.geU(xv, yv)
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* @section Bitwise logic: Boolean operations on the bits of Int64 values.
|
|
507
|
-
*/
|
|
508
|
-
|
|
509
394
|
/**
|
|
510
395
|
* Computes the bitwise NOT of the given value.
|
|
511
396
|
*
|
|
@@ -515,9 +400,9 @@ export let gteU = (x: Int64, y: Int64) => {
|
|
|
515
400
|
* @since v0.2.0
|
|
516
401
|
*/
|
|
517
402
|
@unsafe
|
|
518
|
-
|
|
403
|
+
provide let lnot = (value: Int64) => {
|
|
519
404
|
let xv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
520
|
-
let ptr = newInt64(
|
|
405
|
+
let ptr = newInt64(xv ^ 0xffffffffffffffffN)
|
|
521
406
|
WasmI32.toGrain(ptr): Int64
|
|
522
407
|
}
|
|
523
408
|
|
|
@@ -528,13 +413,14 @@ export let lnot = (value: Int64) => {
|
|
|
528
413
|
* @param y: The second operand
|
|
529
414
|
* @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
|
|
530
415
|
*
|
|
531
|
-
* @since v0.
|
|
416
|
+
* @since v0.6.0
|
|
417
|
+
* @history v0.2.0: Originally named `land`
|
|
532
418
|
*/
|
|
533
419
|
@unsafe
|
|
534
|
-
|
|
420
|
+
provide let (&) = (x: Int64, y: Int64) => {
|
|
535
421
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
536
422
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
537
|
-
let ptr = newInt64(
|
|
423
|
+
let ptr = newInt64(xv & yv)
|
|
538
424
|
WasmI32.toGrain(ptr): Int64
|
|
539
425
|
}
|
|
540
426
|
|
|
@@ -545,13 +431,14 @@ export let land = (x: Int64, y: Int64) => {
|
|
|
545
431
|
* @param y: The second operand
|
|
546
432
|
* @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
|
|
547
433
|
*
|
|
548
|
-
* @since v0.
|
|
434
|
+
* @since v0.6.0
|
|
435
|
+
* @history v0.2.0: Originally named `lor`
|
|
549
436
|
*/
|
|
550
437
|
@unsafe
|
|
551
|
-
|
|
438
|
+
provide let (|) = (x: Int64, y: Int64) => {
|
|
552
439
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
553
440
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
554
|
-
let ptr = newInt64(
|
|
441
|
+
let ptr = newInt64(xv | yv)
|
|
555
442
|
WasmI32.toGrain(ptr): Int64
|
|
556
443
|
}
|
|
557
444
|
|
|
@@ -562,13 +449,14 @@ export let lor = (x: Int64, y: Int64) => {
|
|
|
562
449
|
* @param y: The second operand
|
|
563
450
|
* @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
|
|
564
451
|
*
|
|
565
|
-
* @since v0.
|
|
452
|
+
* @since v0.6.0
|
|
453
|
+
* @history v0.2.0: Originally named `lxor`
|
|
566
454
|
*/
|
|
567
455
|
@unsafe
|
|
568
|
-
|
|
456
|
+
provide let (^) = (x: Int64, y: Int64) => {
|
|
569
457
|
let xv = WasmI64.load(WasmI32.fromGrain(x), 8n)
|
|
570
458
|
let yv = WasmI64.load(WasmI32.fromGrain(y), 8n)
|
|
571
|
-
let ptr = newInt64(
|
|
459
|
+
let ptr = newInt64(xv ^ yv)
|
|
572
460
|
WasmI32.toGrain(ptr): Int64
|
|
573
461
|
}
|
|
574
462
|
|
|
@@ -581,7 +469,7 @@ export let lxor = (x: Int64, y: Int64) => {
|
|
|
581
469
|
* @since v0.4.0
|
|
582
470
|
*/
|
|
583
471
|
@unsafe
|
|
584
|
-
|
|
472
|
+
provide let clz = (value: Int64) => {
|
|
585
473
|
let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
586
474
|
let ptr = newInt64(WasmI64.clz(nv))
|
|
587
475
|
WasmI32.toGrain(ptr): Int64
|
|
@@ -596,7 +484,7 @@ export let clz = (value: Int64) => {
|
|
|
596
484
|
* @since v0.4.0
|
|
597
485
|
*/
|
|
598
486
|
@unsafe
|
|
599
|
-
|
|
487
|
+
provide let ctz = (value: Int64) => {
|
|
600
488
|
let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
601
489
|
let ptr = newInt64(WasmI64.ctz(nv))
|
|
602
490
|
WasmI32.toGrain(ptr): Int64
|
|
@@ -611,8 +499,37 @@ export let ctz = (value: Int64) => {
|
|
|
611
499
|
* @since v0.4.0
|
|
612
500
|
*/
|
|
613
501
|
@unsafe
|
|
614
|
-
|
|
502
|
+
provide let popcnt = (value: Int64) => {
|
|
615
503
|
let nv = WasmI64.load(WasmI32.fromGrain(value), 8n)
|
|
616
504
|
let ptr = newInt64(WasmI64.popcnt(nv))
|
|
617
505
|
WasmI32.toGrain(ptr): Int64
|
|
618
506
|
}
|
|
507
|
+
|
|
508
|
+
// Exponentiation by squaring https://en.wikipedia.org/wiki/Exponentiation_by_squaring special path for int^int
|
|
509
|
+
let rec expBySquaring = (y, x, n) => {
|
|
510
|
+
if (n == 0L) {
|
|
511
|
+
1L
|
|
512
|
+
} else if (n == 1L) {
|
|
513
|
+
x * y
|
|
514
|
+
} else if (n % 2L == 0L) {
|
|
515
|
+
expBySquaring(y, x * x, n / 2L)
|
|
516
|
+
} else {
|
|
517
|
+
expBySquaring(x * y, x * x, (n - 1L) / 2L)
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Computes the exponentiation of the given base and power.
|
|
523
|
+
*
|
|
524
|
+
* @param base: The base number
|
|
525
|
+
* @param power: The exponent number
|
|
526
|
+
* @returns The base raised to the given power
|
|
527
|
+
*
|
|
528
|
+
* @since v0.6.0
|
|
529
|
+
*/
|
|
530
|
+
provide let (**) = (base, power) => {
|
|
531
|
+
if (power < 0L)
|
|
532
|
+
return expBySquaring(1L, 1L / base, power * -1L)
|
|
533
|
+
else
|
|
534
|
+
return expBySquaring(1L, base, power)
|
|
535
|
+
}
|