@grain/stdlib 0.4.5 → 0.5.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 +87 -0
- package/LICENSE +1 -1
- package/array.gr +18 -18
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +49 -213
- package/buffer.md +24 -17
- package/bytes.gr +100 -202
- package/bytes.md +19 -0
- package/char.gr +63 -133
- package/exception.md +6 -0
- package/float32.gr +159 -82
- package/float32.md +315 -0
- package/float64.gr +163 -82
- package/float64.md +315 -0
- package/hash.gr +37 -37
- package/int32.gr +479 -230
- package/int32.md +937 -0
- package/int64.gr +479 -230
- package/int64.md +937 -0
- package/list.gr +467 -70
- package/list.md +1141 -0
- package/map.gr +192 -7
- package/map.md +525 -0
- package/number.gr +30 -54
- package/number.md +3 -3
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +499 -59
- package/pervasives.md +1116 -0
- package/queue.gr +4 -0
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -278
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +5 -23
- package/runtime/equal.md +6 -0
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +20 -3
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +13 -11
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +93 -41
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1043 -391
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +136 -230
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +58 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +9 -8
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +1 -1
- package/runtime/wasi.md +839 -0
- package/set.gr +17 -8
- package/set.md +24 -21
- package/stack.gr +3 -3
- package/stack.md +4 -6
- package/string.gr +196 -331
- package/string.md +3 -3
- package/sys/file.gr +246 -430
- package/sys/process.gr +27 -45
- package/sys/random.gr +47 -16
- package/sys/random.md +38 -0
- package/sys/time.gr +11 -27
package/char.gr
CHANGED
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import WasmI32 from "runtime/unsafe/wasmi32"
|
|
12
|
-
import Memory from "runtime/unsafe/memory"
|
|
13
12
|
import Errors from "runtime/unsafe/errors"
|
|
13
|
+
import Tags from "runtime/unsafe/tags"
|
|
14
14
|
import {
|
|
15
15
|
tagSimpleNumber,
|
|
16
|
-
|
|
16
|
+
tagChar,
|
|
17
|
+
untagChar,
|
|
17
18
|
allocateString,
|
|
18
19
|
} from "runtime/dataStructures"
|
|
19
20
|
|
|
@@ -58,71 +59,13 @@ export let isValid = charCode => {
|
|
|
58
59
|
*
|
|
59
60
|
* @since 0.3.0
|
|
60
61
|
*/
|
|
61
|
-
@
|
|
62
|
-
export let
|
|
63
|
-
|
|
62
|
+
@unsafe
|
|
63
|
+
export let code = (char: Char) => {
|
|
64
|
+
let usv = untagChar(char)
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
let (==) = WasmI32.eq
|
|
69
|
-
let (>=) = WasmI32.geU
|
|
70
|
-
let (<=) = WasmI32.leU
|
|
71
|
-
let (<<) = WasmI32.shl
|
|
72
|
-
let (&) = WasmI32.and
|
|
73
|
-
let (|) = WasmI32.or
|
|
74
|
-
|
|
75
|
-
let mut codePoint = 0n
|
|
76
|
-
let mut bytesSeen = 0n
|
|
77
|
-
let mut bytesNeeded = 0n
|
|
78
|
-
let mut lowerBoundary = 0x80n
|
|
79
|
-
let mut upperBoundary = 0xBFn
|
|
80
|
-
|
|
81
|
-
let mut offset = 0n
|
|
82
|
-
|
|
83
|
-
let mut result = 0n
|
|
84
|
-
|
|
85
|
-
while (true) {
|
|
86
|
-
let byte = WasmI32.load8U(char + offset, 4n)
|
|
87
|
-
offset += 1n
|
|
88
|
-
if (bytesNeeded == 0n) {
|
|
89
|
-
if (byte >= 0x00n && byte <= 0x7Fn) {
|
|
90
|
-
result = byte
|
|
91
|
-
break
|
|
92
|
-
} else if (byte >= 0xC2n && byte <= 0xDFn) {
|
|
93
|
-
bytesNeeded = 1n
|
|
94
|
-
codePoint = byte & 0x1Fn
|
|
95
|
-
} else if (byte >= 0xE0n && byte <= 0xEFn) {
|
|
96
|
-
if (byte == 0xE0n) lowerBoundary = 0xA0n
|
|
97
|
-
if (byte == 0xEDn) upperBoundary = 0x9Fn
|
|
98
|
-
bytesNeeded = 2n
|
|
99
|
-
codePoint = byte & 0xFn
|
|
100
|
-
} else if (byte >= 0xF0n && byte <= 0xF4n) {
|
|
101
|
-
if (byte == 0xF0n) lowerBoundary = 0x90n
|
|
102
|
-
if (byte == 0xF4n) upperBoundary = 0x8Fn
|
|
103
|
-
bytesNeeded = 3n
|
|
104
|
-
codePoint = byte & 0x7n
|
|
105
|
-
} else {
|
|
106
|
-
throw MalformedUtf8
|
|
107
|
-
}
|
|
108
|
-
continue
|
|
109
|
-
}
|
|
110
|
-
if (!(lowerBoundary <= byte && byte <= upperBoundary)) {
|
|
111
|
-
throw MalformedUtf8
|
|
112
|
-
}
|
|
113
|
-
lowerBoundary = 0x80n
|
|
114
|
-
upperBoundary = 0xBFn
|
|
115
|
-
codePoint = codePoint << 6n | byte & 0x3Fn
|
|
116
|
-
bytesSeen += 1n
|
|
117
|
-
if (bytesSeen == bytesNeeded) {
|
|
118
|
-
result = codePoint
|
|
119
|
-
break
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
Memory.decRef(char)
|
|
124
|
-
Memory.decRef(WasmI32.fromGrain(code))
|
|
125
|
-
tagSimpleNumber(result)
|
|
66
|
+
// This could save an instruction by combining the two tagging operations,
|
|
67
|
+
// though we stick with tagSimpleNumber for simplicity.
|
|
68
|
+
tagSimpleNumber(usv)
|
|
126
69
|
}
|
|
127
70
|
|
|
128
71
|
/**
|
|
@@ -134,62 +77,26 @@ export let rec code = (char: Char) => {
|
|
|
134
77
|
*
|
|
135
78
|
* @since 0.3.0
|
|
136
79
|
*/
|
|
137
|
-
@
|
|
138
|
-
export let
|
|
139
|
-
// Algorithm from https://encoding.spec.whatwg.org/#utf-8-encoder
|
|
140
|
-
|
|
141
|
-
let (+) = WasmI32.add
|
|
80
|
+
@unsafe
|
|
81
|
+
export let fromCode = (usv: Number) => {
|
|
142
82
|
let (-) = WasmI32.sub
|
|
143
|
-
let (
|
|
144
|
-
let (==) = WasmI32.eq
|
|
145
|
-
let (>) = WasmI32.gtU
|
|
146
|
-
let (<=) = WasmI32.leU
|
|
147
|
-
let (<) = WasmI32.ltU
|
|
148
|
-
let (>>>) = WasmI32.shrU
|
|
149
|
-
let (&) = WasmI32.and
|
|
150
|
-
let (|) = WasmI32.or
|
|
83
|
+
let (<<) = WasmI32.shl
|
|
151
84
|
|
|
152
|
-
|
|
153
|
-
if ((usv & 1n) == 0n) {
|
|
85
|
+
if (!isValid(usv)) {
|
|
154
86
|
throw InvalidArgument("Invalid character code")
|
|
155
87
|
}
|
|
156
88
|
|
|
157
|
-
|
|
158
|
-
let
|
|
159
|
-
let char = allocateChar()
|
|
160
|
-
WasmI32.store8(char, usv, 4n)
|
|
161
|
-
WasmI32.toGrain(char): Char
|
|
162
|
-
} else {
|
|
163
|
-
let mut count = 0n
|
|
164
|
-
let mut offset = 0n
|
|
165
|
-
if (usv <= 0x07FFn) {
|
|
166
|
-
count = 1n
|
|
167
|
-
offset = 0xC0n
|
|
168
|
-
} else if (usv <= 0xFFFFn) {
|
|
169
|
-
count = 2n
|
|
170
|
-
offset = 0xE0n
|
|
171
|
-
} else {
|
|
172
|
-
count = 3n
|
|
173
|
-
offset = 0xF0n
|
|
174
|
-
}
|
|
175
|
-
let char = allocateChar()
|
|
176
|
-
WasmI32.store8(char, (usv >>> 6n * count) + offset, 4n)
|
|
177
|
-
|
|
178
|
-
let mut n = 0n
|
|
179
|
-
while (count > 0n) {
|
|
180
|
-
n += 1n
|
|
181
|
-
let temp = usv >>> 6n * (count - 1n)
|
|
182
|
-
WasmI32.store8(char + n, 0x80n | temp & 0x3Fn, 4n)
|
|
183
|
-
count -= 1n
|
|
184
|
-
}
|
|
89
|
+
// usv is now guaranteed to be a simple number
|
|
90
|
+
let usv = WasmI32.fromGrain(usv)
|
|
185
91
|
|
|
186
|
-
|
|
187
|
-
|
|
92
|
+
// Here we use a math trick to avoid fully untagging and retagging.
|
|
93
|
+
// Simple numbers are represented as 2n + 1 and chars are represented as
|
|
94
|
+
// 8n + 2. Quick reminder that shifting left is the equivalent of multiplying
|
|
95
|
+
// by 2, and that _GRAIN_CHAR_TAG_TYPE is equal to 2:
|
|
96
|
+
// 4(2n + 1) - 2 = 8n + 2
|
|
97
|
+
let char = (usv << 2n) - Tags._GRAIN_CHAR_TAG_TYPE
|
|
188
98
|
|
|
189
|
-
|
|
190
|
-
// no need to decRef it
|
|
191
|
-
Memory.decRef(WasmI32.fromGrain(fromCode))
|
|
192
|
-
result
|
|
99
|
+
WasmI32.toGrain(char): Char
|
|
193
100
|
}
|
|
194
101
|
|
|
195
102
|
/**
|
|
@@ -240,27 +147,50 @@ export let pred = char => {
|
|
|
240
147
|
*
|
|
241
148
|
* @since 0.3.0
|
|
242
149
|
*/
|
|
243
|
-
@
|
|
244
|
-
export let
|
|
150
|
+
@unsafe
|
|
151
|
+
export let toString = (char: Char) => {
|
|
245
152
|
let (+) = WasmI32.add
|
|
153
|
+
let (-) = WasmI32.sub
|
|
154
|
+
let (*) = WasmI32.mul
|
|
246
155
|
let (&) = WasmI32.and
|
|
247
|
-
let (
|
|
156
|
+
let (|) = WasmI32.or
|
|
157
|
+
let (>>>) = WasmI32.shrU
|
|
158
|
+
let (<) = WasmI32.ltU
|
|
159
|
+
let (>) = WasmI32.gtU
|
|
160
|
+
let (<=) = WasmI32.leU
|
|
161
|
+
|
|
162
|
+
let usv = untagChar(char)
|
|
248
163
|
|
|
249
|
-
let
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
} else if ((byte & 0xF0n) == 0xF0n) {
|
|
254
|
-
4n
|
|
255
|
-
} else if ((byte & 0xE0n) == 0xE0n) {
|
|
256
|
-
3n
|
|
164
|
+
let result = if (usv < 0x80n) {
|
|
165
|
+
let string = allocateString(1n)
|
|
166
|
+
WasmI32.store8(string, usv, 8n)
|
|
167
|
+
WasmI32.toGrain(string): String
|
|
257
168
|
} else {
|
|
258
|
-
|
|
169
|
+
let mut count = 0n
|
|
170
|
+
let mut offset = 0n
|
|
171
|
+
if (usv <= 0x07FFn) {
|
|
172
|
+
count = 1n
|
|
173
|
+
offset = 0xC0n
|
|
174
|
+
} else if (usv <= 0xFFFFn) {
|
|
175
|
+
count = 2n
|
|
176
|
+
offset = 0xE0n
|
|
177
|
+
} else {
|
|
178
|
+
count = 3n
|
|
179
|
+
offset = 0xF0n
|
|
180
|
+
}
|
|
181
|
+
let string = allocateString(count + 1n)
|
|
182
|
+
WasmI32.store8(string, (usv >>> 6n * count) + offset, 8n)
|
|
183
|
+
|
|
184
|
+
let mut n = 0n
|
|
185
|
+
while (count > 0n) {
|
|
186
|
+
n += 1n
|
|
187
|
+
let temp = usv >>> 6n * (count - 1n)
|
|
188
|
+
WasmI32.store8(string + n, 0x80n | temp & 0x3Fn, 8n)
|
|
189
|
+
count -= 1n
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
WasmI32.toGrain(string): String
|
|
259
193
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
let ret = WasmI32.toGrain(str): String
|
|
263
|
-
Memory.decRef(WasmI32.fromGrain(char))
|
|
264
|
-
Memory.decRef(WasmI32.fromGrain(toString))
|
|
265
|
-
ret
|
|
194
|
+
|
|
195
|
+
result
|
|
266
196
|
}
|
package/exception.md
ADDED
package/float32.gr
CHANGED
|
@@ -1,131 +1,208 @@
|
|
|
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
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
newFloat32
|
|
6
|
-
} from "runtime/dataStructures"
|
|
9
|
+
import { newFloat32 } from "runtime/dataStructures"
|
|
7
10
|
|
|
8
11
|
import {
|
|
9
12
|
coerceNumberToFloat32 as fromNumber,
|
|
10
|
-
coerceFloat32ToNumber as toNumber
|
|
13
|
+
coerceFloat32ToNumber as toNumber,
|
|
11
14
|
} from "runtime/numbers"
|
|
12
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @section Conversions: Functions for converting between Numbers and the Float32 type.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Converts a Number to a Float32.
|
|
22
|
+
*
|
|
23
|
+
* @param number: The value to convert
|
|
24
|
+
* @returns The Number represented as a Float32
|
|
25
|
+
*
|
|
26
|
+
* @since v0.2.0
|
|
27
|
+
*/
|
|
13
28
|
export fromNumber
|
|
14
|
-
export toNumber
|
|
15
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Converts a Float32 to a Number.
|
|
32
|
+
*
|
|
33
|
+
* @param float: The value to convert
|
|
34
|
+
* @returns The Float32 represented as a Number
|
|
35
|
+
*
|
|
36
|
+
* @since v0.2.0
|
|
37
|
+
*/
|
|
38
|
+
export toNumber
|
|
16
39
|
|
|
17
|
-
|
|
18
|
-
|
|
40
|
+
/**
|
|
41
|
+
* @section Operations: Mathematical operations for Float32 values.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Computes the sum of its operands.
|
|
46
|
+
*
|
|
47
|
+
* @param x: The first operand
|
|
48
|
+
* @param y: The second operand
|
|
49
|
+
* @returns The sum of the two operands
|
|
50
|
+
*
|
|
51
|
+
* @since v0.2.0
|
|
52
|
+
*/
|
|
53
|
+
@unsafe
|
|
54
|
+
export let add = (x: Float32, y: Float32) => {
|
|
19
55
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
20
56
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
21
57
|
let ptr = newFloat32(WasmF32.add(xv, yv))
|
|
22
|
-
|
|
23
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
24
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
25
|
-
Memory.decRef(WasmI32.fromGrain(add))
|
|
26
|
-
ret
|
|
58
|
+
WasmI32.toGrain(ptr): Float32
|
|
27
59
|
}
|
|
28
60
|
|
|
29
|
-
|
|
30
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Computes the difference of its operands.
|
|
63
|
+
*
|
|
64
|
+
* @param x: The first operand
|
|
65
|
+
* @param y: The second operand
|
|
66
|
+
* @returns The difference of the two operands
|
|
67
|
+
*
|
|
68
|
+
* @since v0.2.0
|
|
69
|
+
*/
|
|
70
|
+
@unsafe
|
|
71
|
+
export let sub = (x: Float32, y: Float32) => {
|
|
31
72
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
32
73
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
33
74
|
let ptr = newFloat32(WasmF32.sub(xv, yv))
|
|
34
|
-
|
|
35
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
36
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
37
|
-
Memory.decRef(WasmI32.fromGrain(sub))
|
|
38
|
-
ret
|
|
75
|
+
WasmI32.toGrain(ptr): Float32
|
|
39
76
|
}
|
|
40
77
|
|
|
41
|
-
|
|
42
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Computes the product of its operands.
|
|
80
|
+
*
|
|
81
|
+
* @param x: The first operand
|
|
82
|
+
* @param y: The second operand
|
|
83
|
+
* @returns The product of the two operands
|
|
84
|
+
*
|
|
85
|
+
* @since v0.2.0
|
|
86
|
+
*/
|
|
87
|
+
@unsafe
|
|
88
|
+
export let mul = (x: Float32, y: Float32) => {
|
|
43
89
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
44
90
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
45
91
|
let ptr = newFloat32(WasmF32.mul(xv, yv))
|
|
46
|
-
|
|
47
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
48
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
49
|
-
Memory.decRef(WasmI32.fromGrain(mul))
|
|
50
|
-
ret
|
|
92
|
+
WasmI32.toGrain(ptr): Float32
|
|
51
93
|
}
|
|
52
94
|
|
|
53
|
-
|
|
54
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Computes the quotient of its operands.
|
|
97
|
+
*
|
|
98
|
+
* @param x: The first operand
|
|
99
|
+
* @param y: The second operand
|
|
100
|
+
* @returns The quotient of the two operands
|
|
101
|
+
*
|
|
102
|
+
* @since v0.2.0
|
|
103
|
+
*/
|
|
104
|
+
@unsafe
|
|
105
|
+
export let div = (x: Float32, y: Float32) => {
|
|
55
106
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
56
107
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
57
108
|
let ptr = newFloat32(WasmF32.div(xv, yv))
|
|
58
|
-
|
|
59
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
60
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
61
|
-
Memory.decRef(WasmI32.fromGrain(div))
|
|
62
|
-
ret
|
|
109
|
+
WasmI32.toGrain(ptr): Float32
|
|
63
110
|
}
|
|
64
111
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @section Comparisons: Functions for comparing Float32 values.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Checks if the first value is less than the second value.
|
|
118
|
+
*
|
|
119
|
+
* @param x: The first value
|
|
120
|
+
* @param y: The second value
|
|
121
|
+
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
122
|
+
*
|
|
123
|
+
* @since v0.2.0
|
|
124
|
+
*/
|
|
125
|
+
@unsafe
|
|
126
|
+
export let lt = (x: Float32, y: Float32) => {
|
|
69
127
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
70
128
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
71
|
-
|
|
72
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
73
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
74
|
-
Memory.decRef(WasmI32.fromGrain(lt))
|
|
75
|
-
ret
|
|
129
|
+
WasmF32.lt(xv, yv)
|
|
76
130
|
}
|
|
77
131
|
|
|
78
|
-
|
|
79
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Checks if the first value is greater than the second value.
|
|
134
|
+
*
|
|
135
|
+
* @param x: The first value
|
|
136
|
+
* @param y: The second value
|
|
137
|
+
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
138
|
+
*
|
|
139
|
+
* @since v0.2.0
|
|
140
|
+
*/
|
|
141
|
+
@unsafe
|
|
142
|
+
export let gt = (x: Float32, y: Float32) => {
|
|
80
143
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
81
144
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
82
|
-
|
|
83
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
84
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
85
|
-
Memory.decRef(WasmI32.fromGrain(gt))
|
|
86
|
-
ret
|
|
145
|
+
WasmF32.gt(xv, yv)
|
|
87
146
|
}
|
|
88
147
|
|
|
89
|
-
|
|
90
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Checks if the first value is less than or equal to the second value.
|
|
150
|
+
*
|
|
151
|
+
* @param x: The first value
|
|
152
|
+
* @param y: The second value
|
|
153
|
+
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
154
|
+
*
|
|
155
|
+
* @since v0.2.0
|
|
156
|
+
*/
|
|
157
|
+
@unsafe
|
|
158
|
+
export let lte = (x: Float32, y: Float32) => {
|
|
91
159
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
92
160
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
93
|
-
|
|
94
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
95
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
96
|
-
Memory.decRef(WasmI32.fromGrain(lte))
|
|
97
|
-
ret
|
|
161
|
+
WasmF32.le(xv, yv)
|
|
98
162
|
}
|
|
99
163
|
|
|
100
|
-
|
|
101
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Checks if the first value is greater than or equal to the second value.
|
|
166
|
+
*
|
|
167
|
+
* @param x: The first value
|
|
168
|
+
* @param y: The second value
|
|
169
|
+
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
170
|
+
*
|
|
171
|
+
* @since v0.2.0
|
|
172
|
+
*/
|
|
173
|
+
@unsafe
|
|
174
|
+
export let gte = (x: Float32, y: Float32) => {
|
|
102
175
|
let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
|
|
103
176
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
104
|
-
|
|
105
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
106
|
-
Memory.decRef(WasmI32.fromGrain(y))
|
|
107
|
-
Memory.decRef(WasmI32.fromGrain(gte))
|
|
108
|
-
ret
|
|
177
|
+
WasmF32.ge(xv, yv)
|
|
109
178
|
}
|
|
110
179
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
180
|
+
/**
|
|
181
|
+
* @section Constants: Float32 constant values.
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Infinity represented as a Float32 value.
|
|
186
|
+
*
|
|
187
|
+
* @since v0.4.0
|
|
188
|
+
*/
|
|
189
|
+
@unsafe
|
|
190
|
+
export let infinity = {
|
|
191
|
+
let ptr = newFloat32(
|
|
192
|
+
WasmF32.reinterpretI32(0b01111111100000000000000000000000n)
|
|
193
|
+
)
|
|
194
|
+
WasmI32.toGrain(ptr): Float32
|
|
119
195
|
}
|
|
120
196
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
197
|
+
/**
|
|
198
|
+
* NaN (Not a Number) represented as a Float32 value.
|
|
199
|
+
*
|
|
200
|
+
* @since v0.4.0
|
|
201
|
+
*/
|
|
202
|
+
@unsafe
|
|
203
|
+
export let nan = {
|
|
204
|
+
let ptr = newFloat32(
|
|
205
|
+
WasmF32.reinterpretI32(0b01111111100000000000000000000001n)
|
|
206
|
+
)
|
|
207
|
+
WasmI32.toGrain(ptr): Float32
|
|
129
208
|
}
|
|
130
|
-
|
|
131
|
-
export let nan = makeNaN()
|