@grain/stdlib 0.4.2 → 0.4.6
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 +52 -0
- package/LICENSE +1 -1
- package/array.gr +200 -89
- package/array.md +81 -5
- package/buffer.gr +93 -36
- package/bytes.gr +10 -10
- package/char.gr +112 -56
- package/char.md +200 -0
- package/float32.gr +120 -4
- package/float32.md +315 -0
- package/float64.gr +120 -4
- package/float64.md +315 -0
- package/hash.gr +42 -15
- package/hash.md +44 -0
- package/int32.gr +370 -75
- package/int32.md +833 -0
- package/int64.gr +370 -75
- package/int64.md +833 -0
- package/list.gr +121 -50
- package/map.gr +106 -110
- package/number.gr +37 -1
- package/number.md +66 -0
- package/option.gr +260 -53
- package/option.md +579 -0
- package/package.json +1 -1
- package/pervasives.gr +32 -20
- package/queue.gr +102 -30
- package/queue.md +191 -0
- package/range.gr +26 -26
- package/range.md +1 -1
- package/regex.md +9 -9
- package/result.gr +216 -70
- package/result.md +446 -0
- package/runtime/dataStructures.gr +28 -29
- package/runtime/debug.gr +0 -1
- package/runtime/equal.gr +37 -16
- package/runtime/exception.gr +28 -15
- package/runtime/gc.gr +33 -20
- package/runtime/malloc.gr +19 -11
- package/runtime/numberUtils.gr +208 -103
- package/runtime/numbers.gr +217 -118
- package/runtime/string.gr +98 -39
- package/runtime/stringUtils.gr +176 -0
- package/runtime/unsafe/conv.gr +10 -10
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/tags.gr +2 -2
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi64.gr +78 -50
- package/runtime/wasi.gr +199 -45
- package/set.gr +281 -119
- package/set.md +502 -0
- package/stack.gr +26 -26
- package/string.gr +657 -341
- package/string.md +815 -0
- package/sys/file.gr +356 -177
- package/sys/process.gr +10 -6
- package/sys/random.gr +3 -6
- package/sys/time.gr +3 -3
package/char.gr
CHANGED
|
@@ -1,35 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Char: Utilities for working with the Char type.
|
|
3
|
+
*
|
|
4
|
+
* The Char type represents a single [Unicode scalar value](https://www.unicode.org/glossary/#unicode_scalar_value).
|
|
5
|
+
*
|
|
6
|
+
* @example import Char from "char"
|
|
7
|
+
*
|
|
8
|
+
* @since 0.3.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
1
11
|
import WasmI32 from "runtime/unsafe/wasmi32"
|
|
2
12
|
import Memory from "runtime/unsafe/memory"
|
|
3
13
|
import Errors from "runtime/unsafe/errors"
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
14
|
+
import {
|
|
15
|
+
tagSimpleNumber,
|
|
16
|
+
allocateChar,
|
|
17
|
+
allocateString,
|
|
18
|
+
} from "runtime/dataStructures"
|
|
7
19
|
|
|
8
20
|
exception MalformedUtf8
|
|
9
21
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @section Values: Functions and constants included in the Char module.
|
|
24
|
+
*/
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The minimum valid Unicode scalar value.
|
|
28
|
+
*
|
|
29
|
+
* @since 0.3.0
|
|
30
|
+
*/
|
|
31
|
+
export let min = 0x0000
|
|
32
|
+
/**
|
|
33
|
+
* The maximum valid Unicode scalar value.
|
|
34
|
+
*
|
|
35
|
+
* @since 0.3.0
|
|
36
|
+
*/
|
|
37
|
+
export let max = 0x10FFFF
|
|
17
38
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Determines whether the given character code is a valid Unicode scalar value.
|
|
41
|
+
*
|
|
42
|
+
* @param charCode: The number to check
|
|
43
|
+
* @returns `true` if the number refers to a valid Unicode scalar value or `false` otherwise
|
|
44
|
+
*
|
|
45
|
+
* @since 0.3.0
|
|
46
|
+
*/
|
|
47
|
+
export let isValid = charCode => {
|
|
48
|
+
charCode >= min &&
|
|
49
|
+
(charCode <= 0xD7FF || charCode >= 0xE000) &&
|
|
50
|
+
charCode <= max
|
|
23
51
|
}
|
|
24
52
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Determines the Unicode scalar value for a character.
|
|
55
|
+
*
|
|
56
|
+
* @param char: The character
|
|
57
|
+
* @returns The Unicode scalar value for the given character
|
|
58
|
+
*
|
|
59
|
+
* @since 0.3.0
|
|
60
|
+
*/
|
|
28
61
|
@disableGC
|
|
29
|
-
let rec code = (
|
|
62
|
+
export let rec code = (char: Char) => {
|
|
30
63
|
// Algorithm from https://encoding.spec.whatwg.org/#utf-8-decoder
|
|
31
64
|
|
|
32
|
-
let
|
|
65
|
+
let char = WasmI32.fromGrain(char)
|
|
33
66
|
|
|
34
67
|
let (+) = WasmI32.add
|
|
35
68
|
let (==) = WasmI32.eq
|
|
@@ -50,7 +83,7 @@ let rec code = (c: Char) => {
|
|
|
50
83
|
let mut result = 0n
|
|
51
84
|
|
|
52
85
|
while (true) {
|
|
53
|
-
let byte = WasmI32.load8U(
|
|
86
|
+
let byte = WasmI32.load8U(char + offset, 4n)
|
|
54
87
|
offset += 1n
|
|
55
88
|
if (bytesNeeded == 0n) {
|
|
56
89
|
if (byte >= 0x00n && byte <= 0x7Fn) {
|
|
@@ -79,7 +112,7 @@ let rec code = (c: Char) => {
|
|
|
79
112
|
}
|
|
80
113
|
lowerBoundary = 0x80n
|
|
81
114
|
upperBoundary = 0xBFn
|
|
82
|
-
codePoint =
|
|
115
|
+
codePoint = codePoint << 6n | byte & 0x3Fn
|
|
83
116
|
bytesSeen += 1n
|
|
84
117
|
if (bytesSeen == bytesNeeded) {
|
|
85
118
|
result = codePoint
|
|
@@ -87,16 +120,22 @@ let rec code = (c: Char) => {
|
|
|
87
120
|
}
|
|
88
121
|
}
|
|
89
122
|
|
|
90
|
-
Memory.decRef(
|
|
123
|
+
Memory.decRef(char)
|
|
91
124
|
Memory.decRef(WasmI32.fromGrain(code))
|
|
92
125
|
tagSimpleNumber(result)
|
|
93
126
|
}
|
|
94
127
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Creates a character from the given Unicode scalar value.
|
|
130
|
+
* Throws an exception if the Unicode scalar value is invalid.
|
|
131
|
+
*
|
|
132
|
+
* @param usv: The Unicode scalar value
|
|
133
|
+
* @returns The character for the given Unicode scalar value
|
|
134
|
+
*
|
|
135
|
+
* @since 0.3.0
|
|
136
|
+
*/
|
|
98
137
|
@disableGC
|
|
99
|
-
let rec fromCode = (
|
|
138
|
+
export let rec fromCode = (usv: Number) => {
|
|
100
139
|
// Algorithm from https://encoding.spec.whatwg.org/#utf-8-encoder
|
|
101
140
|
|
|
102
141
|
let (+) = WasmI32.add
|
|
@@ -110,23 +149,23 @@ let rec fromCode = (code: Number) => {
|
|
|
110
149
|
let (&) = WasmI32.and
|
|
111
150
|
let (|) = WasmI32.or
|
|
112
151
|
|
|
113
|
-
let
|
|
114
|
-
if ((
|
|
152
|
+
let usv = WasmI32.fromGrain(usv)
|
|
153
|
+
if ((usv & 1n) == 0n) {
|
|
115
154
|
throw InvalidArgument("Invalid character code")
|
|
116
155
|
}
|
|
117
156
|
|
|
118
|
-
let
|
|
119
|
-
let result = if (
|
|
157
|
+
let usv = usv >>> 1n
|
|
158
|
+
let result = if (usv < 0x80n) {
|
|
120
159
|
let char = allocateChar()
|
|
121
|
-
WasmI32.store8(char,
|
|
160
|
+
WasmI32.store8(char, usv, 4n)
|
|
122
161
|
WasmI32.toGrain(char): Char
|
|
123
162
|
} else {
|
|
124
163
|
let mut count = 0n
|
|
125
164
|
let mut offset = 0n
|
|
126
|
-
if (
|
|
165
|
+
if (usv <= 0x07FFn) {
|
|
127
166
|
count = 1n
|
|
128
167
|
offset = 0xC0n
|
|
129
|
-
} else if (
|
|
168
|
+
} else if (usv <= 0xFFFFn) {
|
|
130
169
|
count = 2n
|
|
131
170
|
offset = 0xE0n
|
|
132
171
|
} else {
|
|
@@ -134,13 +173,13 @@ let rec fromCode = (code: Number) => {
|
|
|
134
173
|
offset = 0xF0n
|
|
135
174
|
}
|
|
136
175
|
let char = allocateChar()
|
|
137
|
-
WasmI32.store8(char, (
|
|
176
|
+
WasmI32.store8(char, (usv >>> 6n * count) + offset, 4n)
|
|
138
177
|
|
|
139
178
|
let mut n = 0n
|
|
140
179
|
while (count > 0n) {
|
|
141
180
|
n += 1n
|
|
142
|
-
let temp =
|
|
143
|
-
WasmI32.store8(char + n, 0x80n |
|
|
181
|
+
let temp = usv >>> 6n * (count - 1n)
|
|
182
|
+
WasmI32.store8(char + n, 0x80n | temp & 0x3Fn, 4n)
|
|
144
183
|
count -= 1n
|
|
145
184
|
}
|
|
146
185
|
|
|
@@ -153,13 +192,19 @@ let rec fromCode = (code: Number) => {
|
|
|
153
192
|
result
|
|
154
193
|
}
|
|
155
194
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Returns the next valid character by Unicode scalar value.
|
|
197
|
+
* Throws if the input character is the max valid Unicode scalar value.
|
|
198
|
+
*
|
|
199
|
+
* @param char: The character
|
|
200
|
+
* @returns The next valid character by Unicode scalar value
|
|
201
|
+
*
|
|
202
|
+
* @since 0.3.0
|
|
203
|
+
*/
|
|
204
|
+
export let succ = char => {
|
|
205
|
+
let codePoint = code(char)
|
|
161
206
|
if (codePoint == max) {
|
|
162
|
-
fail "no valid Unicode
|
|
207
|
+
fail "no valid Unicode scalar value past U+10FFF"
|
|
163
208
|
} else if (codePoint == 0xD7FF) {
|
|
164
209
|
fromCode(0xE000)
|
|
165
210
|
} else {
|
|
@@ -167,13 +212,19 @@ let succ = (c) => {
|
|
|
167
212
|
}
|
|
168
213
|
}
|
|
169
214
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Returns the previous valid character by Unicode scalar value.
|
|
217
|
+
* Throws if the input character is the min valid Unicode scalar value.
|
|
218
|
+
*
|
|
219
|
+
* @param char: The character
|
|
220
|
+
* @returns The previous valid character by Unicode scalar value
|
|
221
|
+
*
|
|
222
|
+
* @since 0.3.0
|
|
223
|
+
*/
|
|
224
|
+
export let pred = char => {
|
|
225
|
+
let codePoint = code(char)
|
|
175
226
|
if (codePoint == min) {
|
|
176
|
-
fail "no valid Unicode
|
|
227
|
+
fail "no valid Unicode scalar value below U+0000"
|
|
177
228
|
} else if (codePoint == 0xE000) {
|
|
178
229
|
fromCode(0xD7FF)
|
|
179
230
|
} else {
|
|
@@ -181,17 +232,22 @@ let pred = (c) => {
|
|
|
181
232
|
}
|
|
182
233
|
}
|
|
183
234
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
235
|
+
/**
|
|
236
|
+
* Converts the given character to a string.
|
|
237
|
+
*
|
|
238
|
+
* @param char: The character to convert
|
|
239
|
+
* @returns A string containing the given character
|
|
240
|
+
*
|
|
241
|
+
* @since 0.3.0
|
|
242
|
+
*/
|
|
187
243
|
@disableGC
|
|
188
|
-
export let rec toString = (
|
|
244
|
+
export let rec toString = (char: Char) => {
|
|
189
245
|
let (+) = WasmI32.add
|
|
190
246
|
let (&) = WasmI32.and
|
|
191
247
|
let (==) = WasmI32.eq
|
|
192
248
|
|
|
193
|
-
let
|
|
194
|
-
let byte = WasmI32.load8U(
|
|
249
|
+
let char = WasmI32.fromGrain(char)
|
|
250
|
+
let byte = WasmI32.load8U(char, 4n)
|
|
195
251
|
let n = if ((byte & 0x80n) == 0x00n) {
|
|
196
252
|
1n
|
|
197
253
|
} else if ((byte & 0xF0n) == 0xF0n) {
|
|
@@ -202,9 +258,9 @@ export let rec toString = (c: Char) => {
|
|
|
202
258
|
2n
|
|
203
259
|
}
|
|
204
260
|
let str = allocateString(n)
|
|
205
|
-
Memory.copy(str + 8n,
|
|
261
|
+
Memory.copy(str + 8n, char + 4n, n)
|
|
206
262
|
let ret = WasmI32.toGrain(str): String
|
|
207
|
-
Memory.decRef(WasmI32.fromGrain(
|
|
263
|
+
Memory.decRef(WasmI32.fromGrain(char))
|
|
208
264
|
Memory.decRef(WasmI32.fromGrain(toString))
|
|
209
265
|
ret
|
|
210
266
|
}
|
package/char.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Char
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Utilities for working with the Char type.
|
|
6
|
+
|
|
7
|
+
The Char type represents a single [Unicode scalar value](https://www.unicode.org/glossary/#unicode_scalar_value).
|
|
8
|
+
|
|
9
|
+
<details disabled>
|
|
10
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
11
|
+
No other changes yet.
|
|
12
|
+
</details>
|
|
13
|
+
|
|
14
|
+
```grain
|
|
15
|
+
import Char from "char"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Values
|
|
19
|
+
|
|
20
|
+
Functions and constants included in the Char module.
|
|
21
|
+
|
|
22
|
+
### Char.**min**
|
|
23
|
+
|
|
24
|
+
<details disabled>
|
|
25
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
26
|
+
No other changes yet.
|
|
27
|
+
</details>
|
|
28
|
+
|
|
29
|
+
```grain
|
|
30
|
+
min : Number
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The minimum valid Unicode scalar value.
|
|
34
|
+
|
|
35
|
+
### Char.**max**
|
|
36
|
+
|
|
37
|
+
<details disabled>
|
|
38
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
39
|
+
No other changes yet.
|
|
40
|
+
</details>
|
|
41
|
+
|
|
42
|
+
```grain
|
|
43
|
+
max : Number
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The maximum valid Unicode scalar value.
|
|
47
|
+
|
|
48
|
+
### Char.**isValid**
|
|
49
|
+
|
|
50
|
+
<details disabled>
|
|
51
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
52
|
+
No other changes yet.
|
|
53
|
+
</details>
|
|
54
|
+
|
|
55
|
+
```grain
|
|
56
|
+
isValid : Number -> Bool
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Determines whether the given character code is a valid Unicode scalar value.
|
|
60
|
+
|
|
61
|
+
Parameters:
|
|
62
|
+
|
|
63
|
+
|param|type|description|
|
|
64
|
+
|-----|----|-----------|
|
|
65
|
+
|`charCode`|`Number`|The number to check|
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
|
|
69
|
+
|type|description|
|
|
70
|
+
|----|-----------|
|
|
71
|
+
|`Bool`|`true` if the number refers to a valid Unicode scalar value or `false` otherwise|
|
|
72
|
+
|
|
73
|
+
### Char.**code**
|
|
74
|
+
|
|
75
|
+
<details disabled>
|
|
76
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
77
|
+
No other changes yet.
|
|
78
|
+
</details>
|
|
79
|
+
|
|
80
|
+
```grain
|
|
81
|
+
code : Char -> Number
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Determines the Unicode scalar value for a character.
|
|
85
|
+
|
|
86
|
+
Parameters:
|
|
87
|
+
|
|
88
|
+
|param|type|description|
|
|
89
|
+
|-----|----|-----------|
|
|
90
|
+
|`char`|`Char`|The character|
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
|
|
94
|
+
|type|description|
|
|
95
|
+
|----|-----------|
|
|
96
|
+
|`Number`|The Unicode scalar value for the given character|
|
|
97
|
+
|
|
98
|
+
### Char.**fromCode**
|
|
99
|
+
|
|
100
|
+
<details disabled>
|
|
101
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
102
|
+
No other changes yet.
|
|
103
|
+
</details>
|
|
104
|
+
|
|
105
|
+
```grain
|
|
106
|
+
fromCode : Number -> Char
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Creates a character from the given Unicode scalar value.
|
|
110
|
+
Throws an exception if the Unicode scalar value is invalid.
|
|
111
|
+
|
|
112
|
+
Parameters:
|
|
113
|
+
|
|
114
|
+
|param|type|description|
|
|
115
|
+
|-----|----|-----------|
|
|
116
|
+
|`usv`|`Number`|The Unicode scalar value|
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
|
|
120
|
+
|type|description|
|
|
121
|
+
|----|-----------|
|
|
122
|
+
|`Char`|The character for the given Unicode scalar value|
|
|
123
|
+
|
|
124
|
+
### Char.**succ**
|
|
125
|
+
|
|
126
|
+
<details disabled>
|
|
127
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
128
|
+
No other changes yet.
|
|
129
|
+
</details>
|
|
130
|
+
|
|
131
|
+
```grain
|
|
132
|
+
succ : Char -> Char
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Returns the next valid character by Unicode scalar value.
|
|
136
|
+
Throws if the input character is the max valid Unicode scalar value.
|
|
137
|
+
|
|
138
|
+
Parameters:
|
|
139
|
+
|
|
140
|
+
|param|type|description|
|
|
141
|
+
|-----|----|-----------|
|
|
142
|
+
|`char`|`Char`|The character|
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
|
|
146
|
+
|type|description|
|
|
147
|
+
|----|-----------|
|
|
148
|
+
|`Char`|The next valid character by Unicode scalar value|
|
|
149
|
+
|
|
150
|
+
### Char.**pred**
|
|
151
|
+
|
|
152
|
+
<details disabled>
|
|
153
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
154
|
+
No other changes yet.
|
|
155
|
+
</details>
|
|
156
|
+
|
|
157
|
+
```grain
|
|
158
|
+
pred : Char -> Char
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Returns the previous valid character by Unicode scalar value.
|
|
162
|
+
Throws if the input character is the min valid Unicode scalar value.
|
|
163
|
+
|
|
164
|
+
Parameters:
|
|
165
|
+
|
|
166
|
+
|param|type|description|
|
|
167
|
+
|-----|----|-----------|
|
|
168
|
+
|`char`|`Char`|The character|
|
|
169
|
+
|
|
170
|
+
Returns:
|
|
171
|
+
|
|
172
|
+
|type|description|
|
|
173
|
+
|----|-----------|
|
|
174
|
+
|`Char`|The previous valid character by Unicode scalar value|
|
|
175
|
+
|
|
176
|
+
### Char.**toString**
|
|
177
|
+
|
|
178
|
+
<details disabled>
|
|
179
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
180
|
+
No other changes yet.
|
|
181
|
+
</details>
|
|
182
|
+
|
|
183
|
+
```grain
|
|
184
|
+
toString : Char -> String
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Converts the given character to a string.
|
|
188
|
+
|
|
189
|
+
Parameters:
|
|
190
|
+
|
|
191
|
+
|param|type|description|
|
|
192
|
+
|-----|----|-----------|
|
|
193
|
+
|`char`|`Char`|The character to convert|
|
|
194
|
+
|
|
195
|
+
Returns:
|
|
196
|
+
|
|
197
|
+
|type|description|
|
|
198
|
+
|----|-----------|
|
|
199
|
+
|`String`|A string containing the given character|
|
|
200
|
+
|
package/float32.gr
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Float32: Utilities for working with the Float32 type.
|
|
3
|
+
* @example import Float32 from "float32"
|
|
4
|
+
*
|
|
5
|
+
* @since v0.2.0
|
|
6
|
+
*/
|
|
1
7
|
import WasmI32 from "runtime/unsafe/wasmi32"
|
|
2
8
|
import WasmF32 from "runtime/unsafe/wasmf32"
|
|
3
9
|
import Memory from "runtime/unsafe/memory"
|
|
@@ -10,10 +16,43 @@ import {
|
|
|
10
16
|
coerceFloat32ToNumber as toNumber
|
|
11
17
|
} from "runtime/numbers"
|
|
12
18
|
|
|
19
|
+
/**
|
|
20
|
+
* @section Conversions: Functions for converting between Numbers and the Float32 type.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Converts a Number to a Float32.
|
|
25
|
+
*
|
|
26
|
+
* @param number: The value to convert
|
|
27
|
+
* @returns The Number represented as a Float32
|
|
28
|
+
*
|
|
29
|
+
* @since v0.2.0
|
|
30
|
+
*/
|
|
13
31
|
export fromNumber
|
|
14
|
-
export toNumber
|
|
15
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Converts a Float32 to a Number.
|
|
35
|
+
*
|
|
36
|
+
* @param float: The value to convert
|
|
37
|
+
* @returns The Float32 represented as a Number
|
|
38
|
+
*
|
|
39
|
+
* @since v0.2.0
|
|
40
|
+
*/
|
|
41
|
+
export toNumber
|
|
16
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @section Operations: Mathematical operations for Float32 values.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Computes the sum of its operands.
|
|
49
|
+
*
|
|
50
|
+
* @param x: The first operand
|
|
51
|
+
* @param y: The second operand
|
|
52
|
+
* @returns The sum of the two operands
|
|
53
|
+
*
|
|
54
|
+
* @since v0.2.0
|
|
55
|
+
*/
|
|
17
56
|
@disableGC
|
|
18
57
|
export let rec add = (x: Float32, y: Float32) => {
|
|
19
58
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -26,6 +65,15 @@ export let rec add = (x: Float32, y: Float32) => {
|
|
|
26
65
|
ret
|
|
27
66
|
}
|
|
28
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Computes the difference of its operands.
|
|
70
|
+
*
|
|
71
|
+
* @param x: The first operand
|
|
72
|
+
* @param y: The second operand
|
|
73
|
+
* @returns The difference of the two operands
|
|
74
|
+
*
|
|
75
|
+
* @since v0.2.0
|
|
76
|
+
*/
|
|
29
77
|
@disableGC
|
|
30
78
|
export let rec sub = (x: Float32, y: Float32) => {
|
|
31
79
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -38,6 +86,15 @@ export let rec sub = (x: Float32, y: Float32) => {
|
|
|
38
86
|
ret
|
|
39
87
|
}
|
|
40
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Computes the product of its operands.
|
|
91
|
+
*
|
|
92
|
+
* @param x: The first operand
|
|
93
|
+
* @param y: The second operand
|
|
94
|
+
* @returns The product of the two operands
|
|
95
|
+
*
|
|
96
|
+
* @since v0.2.0
|
|
97
|
+
*/
|
|
41
98
|
@disableGC
|
|
42
99
|
export let rec mul = (x: Float32, y: Float32) => {
|
|
43
100
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -50,6 +107,15 @@ export let rec mul = (x: Float32, y: Float32) => {
|
|
|
50
107
|
ret
|
|
51
108
|
}
|
|
52
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Computes the quotient of its operands.
|
|
112
|
+
*
|
|
113
|
+
* @param x: The first operand
|
|
114
|
+
* @param y: The second operand
|
|
115
|
+
* @returns The quotient of the two operands
|
|
116
|
+
*
|
|
117
|
+
* @since v0.2.0
|
|
118
|
+
*/
|
|
53
119
|
@disableGC
|
|
54
120
|
export let rec div = (x: Float32, y: Float32) => {
|
|
55
121
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -62,8 +128,19 @@ export let rec div = (x: Float32, y: Float32) => {
|
|
|
62
128
|
ret
|
|
63
129
|
}
|
|
64
130
|
|
|
65
|
-
|
|
66
|
-
|
|
131
|
+
/**
|
|
132
|
+
* @section Comparisons: Functions for comparing Float32 values.
|
|
133
|
+
*/
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Checks if the first value is less than the second value.
|
|
137
|
+
*
|
|
138
|
+
* @param x: The first value
|
|
139
|
+
* @param y: The second value
|
|
140
|
+
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
141
|
+
*
|
|
142
|
+
* @since v0.2.0
|
|
143
|
+
*/
|
|
67
144
|
@disableGC
|
|
68
145
|
export let rec lt = (x: Float32, y: Float32) => {
|
|
69
146
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -75,6 +152,15 @@ export let rec lt = (x: Float32, y: Float32) => {
|
|
|
75
152
|
ret
|
|
76
153
|
}
|
|
77
154
|
|
|
155
|
+
/**
|
|
156
|
+
* Checks if the first value is greater than the second value.
|
|
157
|
+
*
|
|
158
|
+
* @param x: The first value
|
|
159
|
+
* @param y: The second value
|
|
160
|
+
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
161
|
+
*
|
|
162
|
+
* @since v0.2.0
|
|
163
|
+
*/
|
|
78
164
|
@disableGC
|
|
79
165
|
export let rec gt = (x: Float32, y: Float32) => {
|
|
80
166
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -86,6 +172,15 @@ export let rec gt = (x: Float32, y: Float32) => {
|
|
|
86
172
|
ret
|
|
87
173
|
}
|
|
88
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Checks if the first value is less than or equal to the second value.
|
|
177
|
+
*
|
|
178
|
+
* @param x: The first value
|
|
179
|
+
* @param y: The second value
|
|
180
|
+
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
181
|
+
*
|
|
182
|
+
* @since v0.2.0
|
|
183
|
+
*/
|
|
89
184
|
@disableGC
|
|
90
185
|
export let rec lte = (x: Float32, y: Float32) => {
|
|
91
186
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -97,6 +192,15 @@ export let rec lte = (x: Float32, y: Float32) => {
|
|
|
97
192
|
ret
|
|
98
193
|
}
|
|
99
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Checks if the first value is greater than or equal to the second value.
|
|
197
|
+
*
|
|
198
|
+
* @param x: The first value
|
|
199
|
+
* @param y: The second value
|
|
200
|
+
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
201
|
+
*
|
|
202
|
+
* @since v0.2.0
|
|
203
|
+
*/
|
|
100
204
|
@disableGC
|
|
101
205
|
export let rec gte = (x: Float32, y: Float32) => {
|
|
102
206
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
@@ -108,7 +212,9 @@ export let rec gte = (x: Float32, y: Float32) => {
|
|
|
108
212
|
ret
|
|
109
213
|
}
|
|
110
214
|
|
|
111
|
-
|
|
215
|
+
/**
|
|
216
|
+
* @section Constants: Float32 constant values.
|
|
217
|
+
*/
|
|
112
218
|
|
|
113
219
|
@disableGC
|
|
114
220
|
let rec makeInfinity = () => {
|
|
@@ -118,6 +224,11 @@ let rec makeInfinity = () => {
|
|
|
118
224
|
ret
|
|
119
225
|
}
|
|
120
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Infinity represented as a Float32 value.
|
|
229
|
+
*
|
|
230
|
+
* @since v0.4.0
|
|
231
|
+
*/
|
|
121
232
|
export let infinity = makeInfinity()
|
|
122
233
|
|
|
123
234
|
@disableGC
|
|
@@ -128,4 +239,9 @@ let rec makeNaN = () => {
|
|
|
128
239
|
ret
|
|
129
240
|
}
|
|
130
241
|
|
|
242
|
+
/**
|
|
243
|
+
* NaN (Not a Number) represented as a Float32 value.
|
|
244
|
+
*
|
|
245
|
+
* @since v0.4.0
|
|
246
|
+
*/
|
|
131
247
|
export let nan = makeNaN()
|