@grain/stdlib 0.5.13 → 0.6.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 +193 -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 +47 -37
- package/hash.md +21 -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 +2084 -0
- package/json.md +608 -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 +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- 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/float32.gr
CHANGED
|
@@ -1,95 +1,72 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Utilities for working with the Float32 type.
|
|
3
|
+
*
|
|
4
|
+
* @example from "float32" include Float32
|
|
5
|
+
*
|
|
6
|
+
* @example 4.0f
|
|
7
|
+
* @example -4.0f
|
|
8
|
+
* @example Infinityf
|
|
9
|
+
* @example NaNf
|
|
10
|
+
*
|
|
5
11
|
* @since v0.2.0
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
module Float32
|
|
14
|
+
|
|
15
|
+
from "runtime/unsafe/wasmi32" include WasmI32
|
|
16
|
+
from "runtime/unsafe/wasmf32" include WasmF32
|
|
17
|
+
use WasmF32.{ (+), (-), (*), (/), (<), (<=), (>), (>=) }
|
|
18
|
+
from "runtime/dataStructures" include DataStructures
|
|
19
|
+
use DataStructures.{ newFloat32 }
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
from "runtime/numbers" include Numbers
|
|
22
|
+
use Numbers.{
|
|
12
23
|
coerceNumberToFloat32 as fromNumber,
|
|
13
24
|
coerceFloat32ToNumber as toNumber,
|
|
14
|
-
}
|
|
25
|
+
}
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
27
|
+
@unsafe
|
|
28
|
+
let _VALUE_OFFSET = 4n
|
|
19
29
|
|
|
20
30
|
/**
|
|
21
31
|
* Infinity represented as a Float32 value.
|
|
22
|
-
*
|
|
32
|
+
* This is an alternative to the `Infinityf` literal.
|
|
33
|
+
*
|
|
23
34
|
* @since v0.4.0
|
|
24
35
|
*/
|
|
25
36
|
@unsafe
|
|
26
|
-
|
|
27
|
-
let ptr = newFloat32(
|
|
28
|
-
WasmF32.reinterpretI32(0b01111111100000000000000000000000n)
|
|
29
|
-
)
|
|
30
|
-
WasmI32.toGrain(ptr): Float32
|
|
31
|
-
}
|
|
37
|
+
provide let infinity = Infinityf
|
|
32
38
|
|
|
33
39
|
/**
|
|
34
40
|
* NaN (Not a Number) represented as a Float32 value.
|
|
35
|
-
*
|
|
41
|
+
* This is an alternative to the `NaNf` literal.
|
|
42
|
+
*
|
|
36
43
|
* @since v0.4.0
|
|
37
44
|
*/
|
|
38
45
|
@unsafe
|
|
39
|
-
|
|
40
|
-
let ptr = newFloat32(
|
|
41
|
-
WasmF32.reinterpretI32(0b01111111100000000000000000000001n)
|
|
42
|
-
)
|
|
43
|
-
WasmI32.toGrain(ptr): Float32
|
|
44
|
-
}
|
|
46
|
+
provide let nan = NaNf
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
49
|
* Pi represented as a Float32 value.
|
|
48
|
-
*
|
|
50
|
+
*
|
|
49
51
|
* @since v0.5.2
|
|
50
52
|
*/
|
|
51
|
-
|
|
53
|
+
provide let pi = 3.1415927f
|
|
52
54
|
|
|
53
55
|
/**
|
|
54
56
|
* Tau represented as a Float32 value.
|
|
55
|
-
*
|
|
57
|
+
*
|
|
56
58
|
* @since v0.5.2
|
|
57
59
|
*/
|
|
58
|
-
|
|
60
|
+
provide let tau = 6.2831853f
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* Euler's number represented as a Float32 value.
|
|
62
|
-
*
|
|
63
|
-
* @since v0.5.2
|
|
64
|
-
*/
|
|
65
|
-
export let e = 2.7182817f
|
|
66
|
-
/**
|
|
67
|
-
* @section Conversions: Functions for converting between Numbers and the Float32 type.
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Converts a Number to a Float32.
|
|
72
64
|
*
|
|
73
|
-
* @
|
|
74
|
-
* @returns The Number represented as a Float32
|
|
75
|
-
*
|
|
76
|
-
* @since v0.2.0
|
|
77
|
-
*/
|
|
78
|
-
export fromNumber
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Converts a Float32 to a Number.
|
|
82
|
-
*
|
|
83
|
-
* @param float: The value to convert
|
|
84
|
-
* @returns The Float32 represented as a Number
|
|
85
|
-
*
|
|
86
|
-
* @since v0.2.0
|
|
65
|
+
* @since v0.5.2
|
|
87
66
|
*/
|
|
88
|
-
|
|
67
|
+
provide let e = 2.7182817f
|
|
89
68
|
|
|
90
|
-
|
|
91
|
-
* @section Operations: Mathematical operations for Float32 values.
|
|
92
|
-
*/
|
|
69
|
+
provide { fromNumber, toNumber }
|
|
93
70
|
|
|
94
71
|
/**
|
|
95
72
|
* Computes the sum of its operands.
|
|
@@ -97,14 +74,19 @@ export toNumber
|
|
|
97
74
|
* @param x: The first operand
|
|
98
75
|
* @param y: The second operand
|
|
99
76
|
* @returns The sum of the two operands
|
|
100
|
-
*
|
|
101
|
-
* @
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* use Float32.{ (+) }
|
|
80
|
+
* assert 1.0f + 1.0f == 2.0f
|
|
81
|
+
*
|
|
82
|
+
* @since v0.6.0
|
|
83
|
+
* @history v0.2.0: Originally named `add`
|
|
102
84
|
*/
|
|
103
85
|
@unsafe
|
|
104
|
-
|
|
105
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
106
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
107
|
-
let ptr = newFloat32(
|
|
86
|
+
provide let (+) = (x: Float32, y: Float32) => {
|
|
87
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
88
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
89
|
+
let ptr = newFloat32(xv + yv)
|
|
108
90
|
WasmI32.toGrain(ptr): Float32
|
|
109
91
|
}
|
|
110
92
|
|
|
@@ -114,14 +96,19 @@ export let add = (x: Float32, y: Float32) => {
|
|
|
114
96
|
* @param x: The first operand
|
|
115
97
|
* @param y: The second operand
|
|
116
98
|
* @returns The difference of the two operands
|
|
117
|
-
*
|
|
118
|
-
* @
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* use Float32.{ (-) }
|
|
102
|
+
* assert 1.0f - 1.0f == 0.0f
|
|
103
|
+
*
|
|
104
|
+
* @since v0.6.0
|
|
105
|
+
* @history v0.2.0: Originally named `sub`
|
|
119
106
|
*/
|
|
120
107
|
@unsafe
|
|
121
|
-
|
|
122
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
123
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
124
|
-
let ptr = newFloat32(
|
|
108
|
+
provide let (-) = (x: Float32, y: Float32) => {
|
|
109
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
110
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
111
|
+
let ptr = newFloat32(xv - yv)
|
|
125
112
|
WasmI32.toGrain(ptr): Float32
|
|
126
113
|
}
|
|
127
114
|
|
|
@@ -131,14 +118,19 @@ export let sub = (x: Float32, y: Float32) => {
|
|
|
131
118
|
* @param x: The first operand
|
|
132
119
|
* @param y: The second operand
|
|
133
120
|
* @returns The product of the two operands
|
|
134
|
-
*
|
|
135
|
-
* @
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* use Float32.{ (*) }
|
|
124
|
+
* assert 2.0f * 2.0f == 4.0f
|
|
125
|
+
*
|
|
126
|
+
* @since v0.6.0
|
|
127
|
+
* @history v0.2.0: Originally named `mul`
|
|
136
128
|
*/
|
|
137
129
|
@unsafe
|
|
138
|
-
|
|
139
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
140
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
141
|
-
let ptr = newFloat32(
|
|
130
|
+
provide let (*) = (x: Float32, y: Float32) => {
|
|
131
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
132
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
133
|
+
let ptr = newFloat32(xv * yv)
|
|
142
134
|
WasmI32.toGrain(ptr): Float32
|
|
143
135
|
}
|
|
144
136
|
|
|
@@ -148,35 +140,41 @@ export let mul = (x: Float32, y: Float32) => {
|
|
|
148
140
|
* @param x: The first operand
|
|
149
141
|
* @param y: The second operand
|
|
150
142
|
* @returns The quotient of the two operands
|
|
151
|
-
*
|
|
152
|
-
* @
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* use Float32.{ (/) }
|
|
146
|
+
* assert 10.0f / 4.0f == 2.5f
|
|
147
|
+
*
|
|
148
|
+
* @since v0.6.0
|
|
149
|
+
* @history v0.2.0: Originally named `div`
|
|
153
150
|
*/
|
|
154
151
|
@unsafe
|
|
155
|
-
|
|
156
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
157
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
158
|
-
let ptr = newFloat32(
|
|
152
|
+
provide let (/) = (x: Float32, y: Float32) => {
|
|
153
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
154
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
155
|
+
let ptr = newFloat32(xv / yv)
|
|
159
156
|
WasmI32.toGrain(ptr): Float32
|
|
160
157
|
}
|
|
161
158
|
|
|
162
|
-
/**
|
|
163
|
-
* @section Comparisons: Functions for comparing Float32 values.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
159
|
/**
|
|
167
160
|
* Checks if the first value is less than the second value.
|
|
168
161
|
*
|
|
169
162
|
* @param x: The first value
|
|
170
163
|
* @param y: The second value
|
|
171
164
|
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* use Float32.{ (<) }
|
|
168
|
+
* assert 1.0f < 2.0f
|
|
169
|
+
*
|
|
170
|
+
* @since v0.6.0
|
|
171
|
+
* @history v0.2.0: Originally named `lt`
|
|
174
172
|
*/
|
|
175
173
|
@unsafe
|
|
176
|
-
|
|
177
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
178
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
179
|
-
|
|
174
|
+
provide let (<) = (x: Float32, y: Float32) => {
|
|
175
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
176
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
177
|
+
xv < yv
|
|
180
178
|
}
|
|
181
179
|
|
|
182
180
|
/**
|
|
@@ -185,14 +183,19 @@ export let lt = (x: Float32, y: Float32) => {
|
|
|
185
183
|
* @param x: The first value
|
|
186
184
|
* @param y: The second value
|
|
187
185
|
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
188
|
-
*
|
|
189
|
-
* @
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* use Float32.{ (>) }
|
|
189
|
+
* assert 2.0f > 1.0f
|
|
190
|
+
*
|
|
191
|
+
* @since v0.6.0
|
|
192
|
+
* @history v0.2.0: Originally named `gt`
|
|
190
193
|
*/
|
|
191
194
|
@unsafe
|
|
192
|
-
|
|
193
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
194
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
195
|
-
|
|
195
|
+
provide let (>) = (x: Float32, y: Float32) => {
|
|
196
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
197
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
198
|
+
xv > yv
|
|
196
199
|
}
|
|
197
200
|
|
|
198
201
|
/**
|
|
@@ -201,14 +204,23 @@ export let gt = (x: Float32, y: Float32) => {
|
|
|
201
204
|
* @param x: The first value
|
|
202
205
|
* @param y: The second value
|
|
203
206
|
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
204
|
-
*
|
|
205
|
-
* @
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* use Float32.{ (<=) }
|
|
210
|
+
* assert -1.0f <= 1.0f
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* use Float32.{ (<=) }
|
|
214
|
+
* assert -2.0f <= -2.0f
|
|
215
|
+
*
|
|
216
|
+
* @since v0.6.0
|
|
217
|
+
* @history v0.2.0: Originally named `lte`
|
|
206
218
|
*/
|
|
207
219
|
@unsafe
|
|
208
|
-
|
|
209
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
210
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
211
|
-
|
|
220
|
+
provide let (<=) = (x: Float32, y: Float32) => {
|
|
221
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
222
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
223
|
+
xv <= yv
|
|
212
224
|
}
|
|
213
225
|
|
|
214
226
|
/**
|
|
@@ -217,12 +229,21 @@ export let lte = (x: Float32, y: Float32) => {
|
|
|
217
229
|
* @param x: The first value
|
|
218
230
|
* @param y: The second value
|
|
219
231
|
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
220
|
-
*
|
|
221
|
-
* @
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* use Float32.{ (>=) }
|
|
235
|
+
* assert 4.0f >= 1.0f
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* use Float32.{ (>=) }
|
|
239
|
+
* assert 3.0f >= 3.0f
|
|
240
|
+
*
|
|
241
|
+
* @since v0.6.0
|
|
242
|
+
* @history v0.2.0: Originally named `gte`
|
|
222
243
|
*/
|
|
223
244
|
@unsafe
|
|
224
|
-
|
|
225
|
-
let xv = WasmF32.load(WasmI32.fromGrain(x),
|
|
226
|
-
let yv = WasmF32.load(WasmI32.fromGrain(y),
|
|
227
|
-
|
|
245
|
+
provide let (>=) = (x: Float32, y: Float32) => {
|
|
246
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
247
|
+
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
248
|
+
xv >= yv
|
|
228
249
|
}
|