@grain/stdlib 0.6.6 → 0.7.0
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 +57 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/array.gr +55 -7
- package/array.md +123 -77
- package/bigint.md +30 -30
- package/buffer.gr +20 -53
- package/buffer.md +47 -47
- package/bytes.gr +111 -35
- package/bytes.md +111 -32
- package/char.gr +201 -99
- package/char.md +361 -34
- package/exception.gr +11 -11
- package/exception.md +26 -1
- package/float32.gr +327 -3
- package/float32.md +606 -19
- package/float64.gr +320 -3
- package/float64.md +606 -19
- package/fs.gr +1082 -0
- package/fs.md +630 -0
- package/hash.gr +142 -88
- package/hash.md +102 -14
- package/int16.md +23 -23
- package/int32.gr +25 -4
- package/int32.md +65 -30
- package/int64.gr +26 -1
- package/int64.md +65 -30
- package/int8.md +23 -23
- package/json.gr +366 -51
- package/json.md +418 -2
- package/list.gr +328 -31
- package/list.md +492 -69
- package/map.gr +20 -12
- package/map.md +44 -38
- package/marshal.gr +41 -40
- package/marshal.md +2 -2
- package/number.gr +159 -30
- package/number.md +215 -38
- package/option.md +21 -21
- package/package.json +5 -3
- package/path.gr +48 -0
- package/path.md +103 -12
- package/pervasives.gr +2 -2
- package/pervasives.md +37 -37
- package/priorityqueue.gr +7 -7
- package/priorityqueue.md +19 -19
- package/queue.gr +183 -29
- package/queue.md +296 -40
- package/random.md +6 -6
- package/range.gr +4 -4
- package/range.md +6 -6
- package/rational.md +16 -16
- package/regex.gr +52 -51
- package/regex.md +11 -11
- package/result.md +16 -16
- package/runtime/atof/common.md +39 -39
- package/runtime/atof/decimal.gr +6 -6
- package/runtime/atof/decimal.md +8 -8
- package/runtime/atof/lemire.gr +5 -5
- package/runtime/atof/lemire.md +1 -1
- package/runtime/atof/parse.gr +16 -16
- package/runtime/atof/parse.md +2 -2
- package/runtime/atof/slow.md +1 -1
- package/runtime/atof/table.md +2 -2
- package/runtime/atoi/parse.gr +3 -3
- package/runtime/atoi/parse.md +1 -1
- package/runtime/bigint.gr +15 -47
- package/runtime/bigint.md +54 -60
- package/runtime/compare.gr +2 -2
- package/runtime/compare.md +1 -1
- package/runtime/dataStructures.md +33 -33
- package/runtime/debugPrint.gr +4 -1
- package/runtime/debugPrint.md +9 -9
- package/runtime/equal.gr +99 -77
- package/runtime/equal.md +1 -1
- package/runtime/exception.gr +62 -82
- package/runtime/exception.md +62 -11
- package/runtime/gc.gr +39 -45
- package/runtime/gc.md +4 -4
- package/runtime/malloc.gr +7 -7
- package/runtime/malloc.md +4 -4
- package/runtime/math/kernel/cos.gr +70 -0
- package/runtime/math/kernel/cos.md +14 -0
- package/runtime/math/kernel/sin.gr +65 -0
- package/runtime/math/kernel/sin.md +14 -0
- package/runtime/math/kernel/tan.gr +136 -0
- package/runtime/math/kernel/tan.md +14 -0
- package/runtime/math/rempio2.gr +244 -0
- package/runtime/math/rempio2.md +14 -0
- package/runtime/math/trig.gr +130 -0
- package/runtime/math/trig.md +28 -0
- package/runtime/math/umuldi.gr +26 -0
- package/runtime/math/umuldi.md +14 -0
- package/runtime/numberUtils.gr +29 -29
- package/runtime/numberUtils.md +12 -12
- package/runtime/numbers.gr +373 -381
- package/runtime/numbers.md +79 -73
- package/runtime/string.gr +37 -105
- package/runtime/string.md +3 -9
- package/runtime/unsafe/constants.md +24 -24
- package/runtime/unsafe/conv.md +13 -13
- package/runtime/unsafe/memory.gr +24 -20
- package/runtime/unsafe/memory.md +27 -7
- package/runtime/unsafe/offsets.gr +36 -0
- package/runtime/unsafe/offsets.md +88 -0
- package/runtime/unsafe/panic.gr +28 -0
- package/runtime/unsafe/panic.md +14 -0
- package/runtime/unsafe/tags.md +32 -32
- package/runtime/unsafe/wasmf32.md +28 -28
- package/runtime/unsafe/wasmf64.md +28 -28
- package/runtime/unsafe/wasmi32.md +47 -47
- package/runtime/unsafe/wasmi64.md +50 -50
- package/runtime/utf8.gr +189 -0
- package/runtime/utf8.md +117 -0
- package/runtime/wasi.gr +4 -2
- package/runtime/wasi.md +138 -138
- package/set.gr +18 -11
- package/set.md +42 -36
- package/stack.gr +171 -2
- package/stack.md +297 -15
- package/string.gr +352 -557
- package/string.md +77 -34
- package/uint16.md +22 -22
- package/uint32.gr +25 -4
- package/uint32.md +63 -28
- package/uint64.gr +25 -5
- package/uint64.md +63 -28
- package/uint8.md +22 -22
- package/uri.gr +57 -53
- package/uri.md +11 -12
- package/wasi/file.gr +67 -59
- package/wasi/file.md +39 -39
- package/wasi/process.md +5 -5
- package/wasi/random.md +3 -3
- package/wasi/time.md +4 -4
- package/runtime/utils/printing.gr +0 -60
- package/runtime/utils/printing.md +0 -26
package/string.md
CHANGED
|
@@ -51,7 +51,7 @@ No other changes yet.
|
|
|
51
51
|
</details>
|
|
52
52
|
|
|
53
53
|
```grain
|
|
54
|
-
concat
|
|
54
|
+
concat: (str1: String, str2: String) => String
|
|
55
55
|
```
|
|
56
56
|
|
|
57
57
|
Concatenate two strings.
|
|
@@ -83,7 +83,7 @@ No other changes yet.
|
|
|
83
83
|
</details>
|
|
84
84
|
|
|
85
85
|
```grain
|
|
86
|
-
length
|
|
86
|
+
length: (string: String) => Number
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Returns the character length of the input string.
|
|
@@ -114,7 +114,7 @@ No other changes yet.
|
|
|
114
114
|
</details>
|
|
115
115
|
|
|
116
116
|
```grain
|
|
117
|
-
byteLength
|
|
117
|
+
byteLength: (string: String) => Number
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
Returns the byte length of the input string.
|
|
@@ -145,7 +145,7 @@ No other changes yet.
|
|
|
145
145
|
</details>
|
|
146
146
|
|
|
147
147
|
```grain
|
|
148
|
-
isEmpty
|
|
148
|
+
isEmpty: (string: String) => Bool
|
|
149
149
|
```
|
|
150
150
|
|
|
151
151
|
Determines if the string contains no characters.
|
|
@@ -170,7 +170,7 @@ No other changes yet.
|
|
|
170
170
|
</details>
|
|
171
171
|
|
|
172
172
|
```grain
|
|
173
|
-
indexOf
|
|
173
|
+
indexOf: (search: String, string: String) => Option<Number>
|
|
174
174
|
```
|
|
175
175
|
|
|
176
176
|
Finds the first position of a substring in the input string.
|
|
@@ -202,7 +202,7 @@ No other changes yet.
|
|
|
202
202
|
</details>
|
|
203
203
|
|
|
204
204
|
```grain
|
|
205
|
-
lastIndexOf
|
|
205
|
+
lastIndexOf: (search: String, string: String) => Option<Number>
|
|
206
206
|
```
|
|
207
207
|
|
|
208
208
|
Finds the last position of a substring in the input string.
|
|
@@ -234,7 +234,7 @@ No other changes yet.
|
|
|
234
234
|
</details>
|
|
235
235
|
|
|
236
236
|
```grain
|
|
237
|
-
charCodeAt
|
|
237
|
+
charCodeAt: (position: Number, string: String) => Number
|
|
238
238
|
```
|
|
239
239
|
|
|
240
240
|
Get the Unicode code point at the position in the input string.
|
|
@@ -276,7 +276,7 @@ No other changes yet.
|
|
|
276
276
|
</details>
|
|
277
277
|
|
|
278
278
|
```grain
|
|
279
|
-
charAt
|
|
279
|
+
charAt: (position: Number, string: String) => Char
|
|
280
280
|
```
|
|
281
281
|
|
|
282
282
|
Get the character at the position in the input string.
|
|
@@ -318,7 +318,7 @@ No other changes yet.
|
|
|
318
318
|
</details>
|
|
319
319
|
|
|
320
320
|
```grain
|
|
321
|
-
explode
|
|
321
|
+
explode: (string: String) => Array<Char>
|
|
322
322
|
```
|
|
323
323
|
|
|
324
324
|
Split a string into its Unicode characters.
|
|
@@ -355,7 +355,7 @@ No other changes yet.
|
|
|
355
355
|
</details>
|
|
356
356
|
|
|
357
357
|
```grain
|
|
358
|
-
implode
|
|
358
|
+
implode: (arr: Array<Char>) => String
|
|
359
359
|
```
|
|
360
360
|
|
|
361
361
|
Create a string from an array of characters.
|
|
@@ -386,7 +386,7 @@ No other changes yet.
|
|
|
386
386
|
</details>
|
|
387
387
|
|
|
388
388
|
```grain
|
|
389
|
-
reverse
|
|
389
|
+
reverse: (string: String) => String
|
|
390
390
|
```
|
|
391
391
|
|
|
392
392
|
Create a string that is the given string reversed.
|
|
@@ -412,7 +412,7 @@ String.reverse("olleH") == "Hello"
|
|
|
412
412
|
### String.**split**
|
|
413
413
|
|
|
414
414
|
```grain
|
|
415
|
-
split
|
|
415
|
+
split: (separator: String, string: String) => Array<String>
|
|
416
416
|
```
|
|
417
417
|
|
|
418
418
|
Split a string by the given separator.
|
|
@@ -457,7 +457,7 @@ String.split(" ", "Hello world") == [> "Hello", "world"]
|
|
|
457
457
|
</details>
|
|
458
458
|
|
|
459
459
|
```grain
|
|
460
|
-
slice
|
|
460
|
+
slice: (start: Number, ?end: Number, string: String) => String
|
|
461
461
|
```
|
|
462
462
|
|
|
463
463
|
Get a portion of a string.
|
|
@@ -507,7 +507,7 @@ No other changes yet.
|
|
|
507
507
|
</details>
|
|
508
508
|
|
|
509
509
|
```grain
|
|
510
|
-
contains
|
|
510
|
+
contains: (search: String, string: String) => Bool
|
|
511
511
|
```
|
|
512
512
|
|
|
513
513
|
Check if a string contains a substring.
|
|
@@ -539,7 +539,7 @@ No other changes yet.
|
|
|
539
539
|
</details>
|
|
540
540
|
|
|
541
541
|
```grain
|
|
542
|
-
startsWith
|
|
542
|
+
startsWith: (search: String, string: String) => Bool
|
|
543
543
|
```
|
|
544
544
|
|
|
545
545
|
Check if a string begins with another string.
|
|
@@ -571,7 +571,7 @@ No other changes yet.
|
|
|
571
571
|
</details>
|
|
572
572
|
|
|
573
573
|
```grain
|
|
574
|
-
endsWith
|
|
574
|
+
endsWith: (search: String, string: String) => Bool
|
|
575
575
|
```
|
|
576
576
|
|
|
577
577
|
Check if a string ends with another string.
|
|
@@ -603,7 +603,7 @@ No other changes yet.
|
|
|
603
603
|
</details>
|
|
604
604
|
|
|
605
605
|
```grain
|
|
606
|
-
replaceFirst
|
|
606
|
+
replaceFirst:
|
|
607
607
|
(searchPattern: String, replacement: String, string: String) => String
|
|
608
608
|
```
|
|
609
609
|
|
|
@@ -637,7 +637,7 @@ No other changes yet.
|
|
|
637
637
|
</details>
|
|
638
638
|
|
|
639
639
|
```grain
|
|
640
|
-
replaceLast
|
|
640
|
+
replaceLast:
|
|
641
641
|
(searchPattern: String, replacement: String, string: String) => String
|
|
642
642
|
```
|
|
643
643
|
|
|
@@ -671,7 +671,7 @@ No other changes yet.
|
|
|
671
671
|
</details>
|
|
672
672
|
|
|
673
673
|
```grain
|
|
674
|
-
replaceAll
|
|
674
|
+
replaceAll:
|
|
675
675
|
(searchPattern: String, replacement: String, string: String) => String
|
|
676
676
|
```
|
|
677
677
|
|
|
@@ -712,7 +712,7 @@ String.replaceAll("🌾", "🌎", "Hello 🌾🌾") == "Hello 🌎🌎"
|
|
|
712
712
|
</details>
|
|
713
713
|
|
|
714
714
|
```grain
|
|
715
|
-
encodeAt
|
|
715
|
+
encodeAt:
|
|
716
716
|
(string: String, encoding: Encoding, dest: Bytes, destPos: Number,
|
|
717
717
|
?includeBom: Bool) => Bytes
|
|
718
718
|
```
|
|
@@ -757,7 +757,7 @@ Throws:
|
|
|
757
757
|
</details>
|
|
758
758
|
|
|
759
759
|
```grain
|
|
760
|
-
encode
|
|
760
|
+
encode: (string: String, encoding: Encoding, ?includeBom: Bool) => Bytes
|
|
761
761
|
```
|
|
762
762
|
|
|
763
763
|
Encodes the given string using the given encoding scheme.
|
|
@@ -791,7 +791,7 @@ Returns:
|
|
|
791
791
|
</details>
|
|
792
792
|
|
|
793
793
|
```grain
|
|
794
|
-
decodeRange
|
|
794
|
+
decodeRange:
|
|
795
795
|
(bytes: Bytes, encoding: Encoding, start: Number, size: Number,
|
|
796
796
|
?keepBom: Bool) => String
|
|
797
797
|
```
|
|
@@ -838,7 +838,7 @@ Throws:
|
|
|
838
838
|
</details>
|
|
839
839
|
|
|
840
840
|
```grain
|
|
841
|
-
decode
|
|
841
|
+
decode: (bytes: Bytes, encoding: Encoding, ?keepBom: Bool) => String
|
|
842
842
|
```
|
|
843
843
|
|
|
844
844
|
Decodes the given byte sequence into a string using the given encoding scheme.
|
|
@@ -865,7 +865,7 @@ No other changes yet.
|
|
|
865
865
|
</details>
|
|
866
866
|
|
|
867
867
|
```grain
|
|
868
|
-
forEachCodePoint
|
|
868
|
+
forEachCodePoint: (fn: (Number => Void), str: String) => Void
|
|
869
869
|
```
|
|
870
870
|
|
|
871
871
|
Iterates over Unicode code points in a string.
|
|
@@ -891,7 +891,7 @@ No other changes yet.
|
|
|
891
891
|
</details>
|
|
892
892
|
|
|
893
893
|
```grain
|
|
894
|
-
forEachCodePointi
|
|
894
|
+
forEachCodePointi: (fn: ((Number, Number) => Void), str: String) => Void
|
|
895
895
|
```
|
|
896
896
|
|
|
897
897
|
Iterates over Unicode code points in a string. This is the same as
|
|
@@ -919,7 +919,7 @@ No other changes yet.
|
|
|
919
919
|
</details>
|
|
920
920
|
|
|
921
921
|
```grain
|
|
922
|
-
forEachChar
|
|
922
|
+
forEachChar: (fn: (Char => Void), str: String) => Void
|
|
923
923
|
```
|
|
924
924
|
|
|
925
925
|
Iterates over Unicode characters in a string.
|
|
@@ -945,7 +945,7 @@ No other changes yet.
|
|
|
945
945
|
</details>
|
|
946
946
|
|
|
947
947
|
```grain
|
|
948
|
-
forEachChari
|
|
948
|
+
forEachChari: (fn: ((Char, Number) => Void), str: String) => Void
|
|
949
949
|
```
|
|
950
950
|
|
|
951
951
|
Iterates over Unicode characters in a string. This is the same as
|
|
@@ -973,7 +973,7 @@ No other changes yet.
|
|
|
973
973
|
</details>
|
|
974
974
|
|
|
975
975
|
```grain
|
|
976
|
-
map
|
|
976
|
+
map: (fn: (Char => Char), str: String) => String
|
|
977
977
|
```
|
|
978
978
|
|
|
979
979
|
Builds a new string by mapping Unicode characters.
|
|
@@ -999,7 +999,7 @@ No other changes yet.
|
|
|
999
999
|
</details>
|
|
1000
1000
|
|
|
1001
1001
|
```grain
|
|
1002
|
-
mapi
|
|
1002
|
+
mapi: (fn: ((Char, Number) => Char), str: String) => String
|
|
1003
1003
|
```
|
|
1004
1004
|
|
|
1005
1005
|
Builds a new string by mapping Unicode characters. This is the same as
|
|
@@ -1027,7 +1027,7 @@ No other changes yet.
|
|
|
1027
1027
|
</details>
|
|
1028
1028
|
|
|
1029
1029
|
```grain
|
|
1030
|
-
trimStart
|
|
1030
|
+
trimStart: (string: String) => String
|
|
1031
1031
|
```
|
|
1032
1032
|
|
|
1033
1033
|
Trims the beginning of a string—removing any leading whitespace characters.
|
|
@@ -1058,7 +1058,7 @@ No other changes yet.
|
|
|
1058
1058
|
</details>
|
|
1059
1059
|
|
|
1060
1060
|
```grain
|
|
1061
|
-
trimEnd
|
|
1061
|
+
trimEnd: (string: String) => String
|
|
1062
1062
|
```
|
|
1063
1063
|
|
|
1064
1064
|
Trims the end of a string—removing any trailing whitespace characters.
|
|
@@ -1089,7 +1089,7 @@ No other changes yet.
|
|
|
1089
1089
|
</details>
|
|
1090
1090
|
|
|
1091
1091
|
```grain
|
|
1092
|
-
trim
|
|
1092
|
+
trim: (string: String) => String
|
|
1093
1093
|
```
|
|
1094
1094
|
|
|
1095
1095
|
Trims a string—removing all leading and trailing whitespace characters.
|
|
@@ -1120,7 +1120,7 @@ No other changes yet.
|
|
|
1120
1120
|
</details>
|
|
1121
1121
|
|
|
1122
1122
|
```grain
|
|
1123
|
-
toAsciiLowercase
|
|
1123
|
+
toAsciiLowercase: (string: String) => String
|
|
1124
1124
|
```
|
|
1125
1125
|
|
|
1126
1126
|
Converts all ASCII uppercase characters in the string to lowercase.
|
|
@@ -1151,7 +1151,7 @@ No other changes yet.
|
|
|
1151
1151
|
</details>
|
|
1152
1152
|
|
|
1153
1153
|
```grain
|
|
1154
|
-
toAsciiUppercase
|
|
1154
|
+
toAsciiUppercase: (string: String) => String
|
|
1155
1155
|
```
|
|
1156
1156
|
|
|
1157
1157
|
Converts all ASCII lowercase characters in the string to uppercase.
|
|
@@ -1174,3 +1174,46 @@ Examples:
|
|
|
1174
1174
|
assert String.toAsciiUppercase("aBc123") == "ABC123"
|
|
1175
1175
|
```
|
|
1176
1176
|
|
|
1177
|
+
### String.**repeat**
|
|
1178
|
+
|
|
1179
|
+
<details disabled>
|
|
1180
|
+
<summary tabindex="-1">Added in <code>0.6.7</code></summary>
|
|
1181
|
+
No other changes yet.
|
|
1182
|
+
</details>
|
|
1183
|
+
|
|
1184
|
+
```grain
|
|
1185
|
+
repeat: (count: Number, string: String) => String
|
|
1186
|
+
```
|
|
1187
|
+
|
|
1188
|
+
Produces a new string by repeating a substring a given number of times.
|
|
1189
|
+
|
|
1190
|
+
Parameters:
|
|
1191
|
+
|
|
1192
|
+
|param|type|description|
|
|
1193
|
+
|-----|----|-----------|
|
|
1194
|
+
|`count`|`Number`|The number of times to repeat the string|
|
|
1195
|
+
|`string`|`String`|The string to repeat|
|
|
1196
|
+
|
|
1197
|
+
Returns:
|
|
1198
|
+
|
|
1199
|
+
|type|description|
|
|
1200
|
+
|----|-----------|
|
|
1201
|
+
|`String`|A string containing the repeated input string|
|
|
1202
|
+
|
|
1203
|
+
Throws:
|
|
1204
|
+
|
|
1205
|
+
`InvalidArgument(String)`
|
|
1206
|
+
|
|
1207
|
+
* When the `count` is not an integer
|
|
1208
|
+
* When the `count` is negative
|
|
1209
|
+
|
|
1210
|
+
Examples:
|
|
1211
|
+
|
|
1212
|
+
```grain
|
|
1213
|
+
assert String.repeat(5, "=") == "====="
|
|
1214
|
+
```
|
|
1215
|
+
|
|
1216
|
+
```grain
|
|
1217
|
+
assert String.repeat(0, ".") == ""
|
|
1218
|
+
```
|
|
1219
|
+
|
package/uint16.md
CHANGED
|
@@ -33,7 +33,7 @@ No other changes yet.
|
|
|
33
33
|
</details>
|
|
34
34
|
|
|
35
35
|
```grain
|
|
36
|
-
fromNumber
|
|
36
|
+
fromNumber: (number: Number) => Uint16
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
Converts a Number to a Uint16.
|
|
@@ -58,7 +58,7 @@ No other changes yet.
|
|
|
58
58
|
</details>
|
|
59
59
|
|
|
60
60
|
```grain
|
|
61
|
-
toNumber
|
|
61
|
+
toNumber: (value: Uint16) => Number
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
Converts a Uint16 to a Number.
|
|
@@ -83,7 +83,7 @@ No other changes yet.
|
|
|
83
83
|
</details>
|
|
84
84
|
|
|
85
85
|
```grain
|
|
86
|
-
fromInt16
|
|
86
|
+
fromInt16: (number: Int16) => Uint16
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Converts an Int16 to a Uint16.
|
|
@@ -118,7 +118,7 @@ No other changes yet.
|
|
|
118
118
|
</details>
|
|
119
119
|
|
|
120
120
|
```grain
|
|
121
|
-
incr
|
|
121
|
+
incr: (value: Uint16) => Uint16
|
|
122
122
|
```
|
|
123
123
|
|
|
124
124
|
Increments the value by one.
|
|
@@ -149,7 +149,7 @@ No other changes yet.
|
|
|
149
149
|
</details>
|
|
150
150
|
|
|
151
151
|
```grain
|
|
152
|
-
decr
|
|
152
|
+
decr: (value: Uint16) => Uint16
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
Decrements the value by one.
|
|
@@ -184,7 +184,7 @@ No other changes yet.
|
|
|
184
184
|
</details>
|
|
185
185
|
|
|
186
186
|
```grain
|
|
187
|
-
(+)
|
|
187
|
+
(+): (x: Uint16, y: Uint16) => Uint16
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
Computes the sum of its operands.
|
|
@@ -217,7 +217,7 @@ No other changes yet.
|
|
|
217
217
|
</details>
|
|
218
218
|
|
|
219
219
|
```grain
|
|
220
|
-
(-)
|
|
220
|
+
(-): (x: Uint16, y: Uint16) => Uint16
|
|
221
221
|
```
|
|
222
222
|
|
|
223
223
|
Computes the difference of its operands.
|
|
@@ -250,7 +250,7 @@ No other changes yet.
|
|
|
250
250
|
</details>
|
|
251
251
|
|
|
252
252
|
```grain
|
|
253
|
-
(*)
|
|
253
|
+
(*): (x: Uint16, y: Uint16) => Uint16
|
|
254
254
|
```
|
|
255
255
|
|
|
256
256
|
Computes the product of its operands.
|
|
@@ -283,7 +283,7 @@ No other changes yet.
|
|
|
283
283
|
</details>
|
|
284
284
|
|
|
285
285
|
```grain
|
|
286
|
-
(/)
|
|
286
|
+
(/): (x: Uint16, y: Uint16) => Uint16
|
|
287
287
|
```
|
|
288
288
|
|
|
289
289
|
Computes the quotient of its operands.
|
|
@@ -316,7 +316,7 @@ No other changes yet.
|
|
|
316
316
|
</details>
|
|
317
317
|
|
|
318
318
|
```grain
|
|
319
|
-
rem
|
|
319
|
+
rem: (x: Uint16, y: Uint16) => Uint16
|
|
320
320
|
```
|
|
321
321
|
|
|
322
322
|
Computes the remainder of the division of its operands.
|
|
@@ -348,7 +348,7 @@ No other changes yet.
|
|
|
348
348
|
</details>
|
|
349
349
|
|
|
350
350
|
```grain
|
|
351
|
-
(<<)
|
|
351
|
+
(<<): (value: Uint16, amount: Uint16) => Uint16
|
|
352
352
|
```
|
|
353
353
|
|
|
354
354
|
Shifts the bits of the value left by the given number of bits.
|
|
@@ -381,7 +381,7 @@ No other changes yet.
|
|
|
381
381
|
</details>
|
|
382
382
|
|
|
383
383
|
```grain
|
|
384
|
-
(>>>)
|
|
384
|
+
(>>>): (value: Uint16, amount: Uint16) => Uint16
|
|
385
385
|
```
|
|
386
386
|
|
|
387
387
|
Shifts the bits of the value right by the given number of bits.
|
|
@@ -414,7 +414,7 @@ No other changes yet.
|
|
|
414
414
|
</details>
|
|
415
415
|
|
|
416
416
|
```grain
|
|
417
|
-
(==)
|
|
417
|
+
(==): (x: Uint16, y: Uint16) => Bool
|
|
418
418
|
```
|
|
419
419
|
|
|
420
420
|
Checks if the first value is equal to the second value.
|
|
@@ -447,7 +447,7 @@ No other changes yet.
|
|
|
447
447
|
</details>
|
|
448
448
|
|
|
449
449
|
```grain
|
|
450
|
-
(!=)
|
|
450
|
+
(!=): (x: Uint16, y: Uint16) => Bool
|
|
451
451
|
```
|
|
452
452
|
|
|
453
453
|
Checks if the first value is not equal to the second value.
|
|
@@ -480,7 +480,7 @@ No other changes yet.
|
|
|
480
480
|
</details>
|
|
481
481
|
|
|
482
482
|
```grain
|
|
483
|
-
(<)
|
|
483
|
+
(<): (x: Uint16, y: Uint16) => Bool
|
|
484
484
|
```
|
|
485
485
|
|
|
486
486
|
Checks if the first value is less than the second value.
|
|
@@ -513,7 +513,7 @@ No other changes yet.
|
|
|
513
513
|
</details>
|
|
514
514
|
|
|
515
515
|
```grain
|
|
516
|
-
(>)
|
|
516
|
+
(>): (x: Uint16, y: Uint16) => Bool
|
|
517
517
|
```
|
|
518
518
|
|
|
519
519
|
Checks if the first value is greater than the second value.
|
|
@@ -546,7 +546,7 @@ No other changes yet.
|
|
|
546
546
|
</details>
|
|
547
547
|
|
|
548
548
|
```grain
|
|
549
|
-
(<=)
|
|
549
|
+
(<=): (x: Uint16, y: Uint16) => Bool
|
|
550
550
|
```
|
|
551
551
|
|
|
552
552
|
Checks if the first value is less than or equal to the second value.
|
|
@@ -584,7 +584,7 @@ No other changes yet.
|
|
|
584
584
|
</details>
|
|
585
585
|
|
|
586
586
|
```grain
|
|
587
|
-
(>=)
|
|
587
|
+
(>=): (x: Uint16, y: Uint16) => Bool
|
|
588
588
|
```
|
|
589
589
|
|
|
590
590
|
Checks if the first value is greater than or equal to the second value.
|
|
@@ -622,7 +622,7 @@ No other changes yet.
|
|
|
622
622
|
</details>
|
|
623
623
|
|
|
624
624
|
```grain
|
|
625
|
-
lnot
|
|
625
|
+
lnot: (value: Uint16) => Uint16
|
|
626
626
|
```
|
|
627
627
|
|
|
628
628
|
Computes the bitwise NOT of the given value.
|
|
@@ -653,7 +653,7 @@ No other changes yet.
|
|
|
653
653
|
</details>
|
|
654
654
|
|
|
655
655
|
```grain
|
|
656
|
-
(&)
|
|
656
|
+
(&): (x: Uint16, y: Uint16) => Uint16
|
|
657
657
|
```
|
|
658
658
|
|
|
659
659
|
Computes the bitwise AND (`&`) on the given operands.
|
|
@@ -686,7 +686,7 @@ No other changes yet.
|
|
|
686
686
|
</details>
|
|
687
687
|
|
|
688
688
|
```grain
|
|
689
|
-
(|)
|
|
689
|
+
(|): (x: Uint16, y: Uint16) => Uint16
|
|
690
690
|
```
|
|
691
691
|
|
|
692
692
|
Computes the bitwise OR (`|`) on the given operands.
|
|
@@ -719,7 +719,7 @@ No other changes yet.
|
|
|
719
719
|
</details>
|
|
720
720
|
|
|
721
721
|
```grain
|
|
722
|
-
(^)
|
|
722
|
+
(^): (x: Uint16, y: Uint16) => Uint16
|
|
723
723
|
```
|
|
724
724
|
|
|
725
725
|
Computes the bitwise XOR (`^`) on the given operands.
|
package/uint32.gr
CHANGED
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
module Uint32
|
|
8
8
|
|
|
9
|
+
from "runtime/unsafe/offsets" include Offsets
|
|
10
|
+
use Offsets.{
|
|
11
|
+
_UINT32_VALUE_OFFSET as _VALUE_OFFSET,
|
|
12
|
+
_INT32_VALUE_OFFSET,
|
|
13
|
+
_FLOAT32_VALUE_OFFSET,
|
|
14
|
+
}
|
|
9
15
|
from "runtime/unsafe/wasmi32" include WasmI32
|
|
10
16
|
use WasmI32.{ (+), (-), (*), (&), (|), (^), (<<), (>>>), (==), (!=) }
|
|
11
17
|
from "runtime/unsafe/wasmi64" include WasmI64
|
|
@@ -16,9 +22,6 @@ use Numbers.{ reducedUnsignedInteger, coerceNumberToUnsignedWasmI32 }
|
|
|
16
22
|
from "runtime/dataStructures" include DataStructures
|
|
17
23
|
use DataStructures.{ newUint32 }
|
|
18
24
|
|
|
19
|
-
@unsafe
|
|
20
|
-
let _VALUE_OFFSET = 4n
|
|
21
|
-
|
|
22
25
|
/**
|
|
23
26
|
* Converts a Number to a Uint32.
|
|
24
27
|
*
|
|
@@ -60,7 +63,25 @@ provide let toNumber = (value: Uint32) => {
|
|
|
60
63
|
*/
|
|
61
64
|
@unsafe
|
|
62
65
|
provide let fromInt32 = (number: Int32) => {
|
|
63
|
-
let x = WasmI32.load(WasmI32.fromGrain(number),
|
|
66
|
+
let x = WasmI32.load(WasmI32.fromGrain(number), _INT32_VALUE_OFFSET)
|
|
67
|
+
let result = newUint32(x)
|
|
68
|
+
WasmI32.toGrain(result): Uint32
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Interprets a Float32 as an Uint32.
|
|
73
|
+
*
|
|
74
|
+
* @param value: The value to convert
|
|
75
|
+
* @returns The Float32 interpreted as an Uint32
|
|
76
|
+
*
|
|
77
|
+
* @example assert Uint32.reinterpretFloat32(1.0f) == 1065353216ul
|
|
78
|
+
* @example assert Uint32.reinterpretFloat32(-1.0f) == 3212836864ul
|
|
79
|
+
*
|
|
80
|
+
* @since v0.7.0
|
|
81
|
+
*/
|
|
82
|
+
@unsafe
|
|
83
|
+
provide let reinterpretFloat32 = (value: Float32) => {
|
|
84
|
+
let x = WasmI32.load(WasmI32.fromGrain(value), _FLOAT32_VALUE_OFFSET)
|
|
64
85
|
let result = newUint32(x)
|
|
65
86
|
WasmI32.toGrain(result): Uint32
|
|
66
87
|
}
|