@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.md
CHANGED
|
@@ -10,12 +10,28 @@ No other changes yet.
|
|
|
10
10
|
</details>
|
|
11
11
|
|
|
12
12
|
```grain
|
|
13
|
-
|
|
13
|
+
from "float32" include Float32
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
```grain
|
|
17
|
+
4.0f
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
```grain
|
|
21
|
+
-4.0f
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```grain
|
|
25
|
+
Infinityf
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```grain
|
|
29
|
+
NaNf
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Values
|
|
17
33
|
|
|
18
|
-
Float32
|
|
34
|
+
Functions and constants included in the Float32 module.
|
|
19
35
|
|
|
20
36
|
### Float32.**infinity**
|
|
21
37
|
|
|
@@ -29,6 +45,7 @@ infinity : Float32
|
|
|
29
45
|
```
|
|
30
46
|
|
|
31
47
|
Infinity represented as a Float32 value.
|
|
48
|
+
This is an alternative to the `Infinityf` literal.
|
|
32
49
|
|
|
33
50
|
### Float32.**nan**
|
|
34
51
|
|
|
@@ -42,6 +59,7 @@ nan : Float32
|
|
|
42
59
|
```
|
|
43
60
|
|
|
44
61
|
NaN (Not a Number) represented as a Float32 value.
|
|
62
|
+
This is an alternative to the `NaNf` literal.
|
|
45
63
|
|
|
46
64
|
### Float32.**pi**
|
|
47
65
|
|
|
@@ -82,10 +100,6 @@ e : Float32
|
|
|
82
100
|
|
|
83
101
|
Euler's number represented as a Float32 value.
|
|
84
102
|
|
|
85
|
-
## Conversions
|
|
86
|
-
|
|
87
|
-
Functions for converting between Numbers and the Float32 type.
|
|
88
|
-
|
|
89
103
|
### Float32.**fromNumber**
|
|
90
104
|
|
|
91
105
|
<details disabled>
|
|
@@ -94,7 +108,7 @@ No other changes yet.
|
|
|
94
108
|
</details>
|
|
95
109
|
|
|
96
110
|
```grain
|
|
97
|
-
fromNumber : Number
|
|
111
|
+
fromNumber : (number: Number) => Float32
|
|
98
112
|
```
|
|
99
113
|
|
|
100
114
|
Converts a Number to a Float32.
|
|
@@ -119,7 +133,7 @@ No other changes yet.
|
|
|
119
133
|
</details>
|
|
120
134
|
|
|
121
135
|
```grain
|
|
122
|
-
toNumber : Float32
|
|
136
|
+
toNumber : (float: Float32) => Number
|
|
123
137
|
```
|
|
124
138
|
|
|
125
139
|
Converts a Float32 to a Number.
|
|
@@ -136,19 +150,22 @@ Returns:
|
|
|
136
150
|
|----|-----------|
|
|
137
151
|
|`Number`|The Float32 represented as a Number|
|
|
138
152
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
### Float32.**(+)**
|
|
154
|
+
|
|
155
|
+
<details>
|
|
156
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
157
|
+
<table>
|
|
158
|
+
<thead>
|
|
159
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
160
|
+
</thead>
|
|
161
|
+
<tbody>
|
|
162
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `add`</td></tr>
|
|
163
|
+
</tbody>
|
|
164
|
+
</table>
|
|
148
165
|
</details>
|
|
149
166
|
|
|
150
167
|
```grain
|
|
151
|
-
|
|
168
|
+
(+) : (x: Float32, y: Float32) => Float32
|
|
152
169
|
```
|
|
153
170
|
|
|
154
171
|
Computes the sum of its operands.
|
|
@@ -166,15 +183,29 @@ Returns:
|
|
|
166
183
|
|----|-----------|
|
|
167
184
|
|`Float32`|The sum of the two operands|
|
|
168
185
|
|
|
169
|
-
|
|
186
|
+
Examples:
|
|
170
187
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
188
|
+
```grain
|
|
189
|
+
use Float32.{ (+) }
|
|
190
|
+
assert 1.0f + 1.0f == 2.0f
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Float32.**(-)**
|
|
194
|
+
|
|
195
|
+
<details>
|
|
196
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
197
|
+
<table>
|
|
198
|
+
<thead>
|
|
199
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
200
|
+
</thead>
|
|
201
|
+
<tbody>
|
|
202
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `sub`</td></tr>
|
|
203
|
+
</tbody>
|
|
204
|
+
</table>
|
|
174
205
|
</details>
|
|
175
206
|
|
|
176
207
|
```grain
|
|
177
|
-
|
|
208
|
+
(-) : (x: Float32, y: Float32) => Float32
|
|
178
209
|
```
|
|
179
210
|
|
|
180
211
|
Computes the difference of its operands.
|
|
@@ -192,15 +223,29 @@ Returns:
|
|
|
192
223
|
|----|-----------|
|
|
193
224
|
|`Float32`|The difference of the two operands|
|
|
194
225
|
|
|
195
|
-
|
|
226
|
+
Examples:
|
|
196
227
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
228
|
+
```grain
|
|
229
|
+
use Float32.{ (-) }
|
|
230
|
+
assert 1.0f - 1.0f == 0.0f
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Float32.**(*)**
|
|
234
|
+
|
|
235
|
+
<details>
|
|
236
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
237
|
+
<table>
|
|
238
|
+
<thead>
|
|
239
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
240
|
+
</thead>
|
|
241
|
+
<tbody>
|
|
242
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `mul`</td></tr>
|
|
243
|
+
</tbody>
|
|
244
|
+
</table>
|
|
200
245
|
</details>
|
|
201
246
|
|
|
202
247
|
```grain
|
|
203
|
-
|
|
248
|
+
(*) : (x: Float32, y: Float32) => Float32
|
|
204
249
|
```
|
|
205
250
|
|
|
206
251
|
Computes the product of its operands.
|
|
@@ -218,15 +263,29 @@ Returns:
|
|
|
218
263
|
|----|-----------|
|
|
219
264
|
|`Float32`|The product of the two operands|
|
|
220
265
|
|
|
221
|
-
|
|
266
|
+
Examples:
|
|
222
267
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
268
|
+
```grain
|
|
269
|
+
use Float32.{ (*) }
|
|
270
|
+
assert 2.0f * 2.0f == 4.0f
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Float32.**(/)**
|
|
274
|
+
|
|
275
|
+
<details>
|
|
276
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
277
|
+
<table>
|
|
278
|
+
<thead>
|
|
279
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
280
|
+
</thead>
|
|
281
|
+
<tbody>
|
|
282
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `div`</td></tr>
|
|
283
|
+
</tbody>
|
|
284
|
+
</table>
|
|
226
285
|
</details>
|
|
227
286
|
|
|
228
287
|
```grain
|
|
229
|
-
|
|
288
|
+
(/) : (x: Float32, y: Float32) => Float32
|
|
230
289
|
```
|
|
231
290
|
|
|
232
291
|
Computes the quotient of its operands.
|
|
@@ -244,19 +303,29 @@ Returns:
|
|
|
244
303
|
|----|-----------|
|
|
245
304
|
|`Float32`|The quotient of the two operands|
|
|
246
305
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
Functions for comparing Float32 values.
|
|
306
|
+
Examples:
|
|
250
307
|
|
|
251
|
-
|
|
308
|
+
```grain
|
|
309
|
+
use Float32.{ (/) }
|
|
310
|
+
assert 10.0f / 4.0f == 2.5f
|
|
311
|
+
```
|
|
252
312
|
|
|
253
|
-
<
|
|
254
|
-
|
|
255
|
-
|
|
313
|
+
### Float32.**(<)**
|
|
314
|
+
|
|
315
|
+
<details>
|
|
316
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
317
|
+
<table>
|
|
318
|
+
<thead>
|
|
319
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
320
|
+
</thead>
|
|
321
|
+
<tbody>
|
|
322
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `lt`</td></tr>
|
|
323
|
+
</tbody>
|
|
324
|
+
</table>
|
|
256
325
|
</details>
|
|
257
326
|
|
|
258
327
|
```grain
|
|
259
|
-
|
|
328
|
+
(<) : (x: Float32, y: Float32) => Bool
|
|
260
329
|
```
|
|
261
330
|
|
|
262
331
|
Checks if the first value is less than the second value.
|
|
@@ -274,15 +343,29 @@ Returns:
|
|
|
274
343
|
|----|-----------|
|
|
275
344
|
|`Bool`|`true` if the first value is less than the second value or `false` otherwise|
|
|
276
345
|
|
|
277
|
-
|
|
346
|
+
Examples:
|
|
278
347
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
348
|
+
```grain
|
|
349
|
+
use Float32.{ (<) }
|
|
350
|
+
assert 1.0f < 2.0f
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### Float32.**(>)**
|
|
354
|
+
|
|
355
|
+
<details>
|
|
356
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
357
|
+
<table>
|
|
358
|
+
<thead>
|
|
359
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
360
|
+
</thead>
|
|
361
|
+
<tbody>
|
|
362
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `gt`</td></tr>
|
|
363
|
+
</tbody>
|
|
364
|
+
</table>
|
|
282
365
|
</details>
|
|
283
366
|
|
|
284
367
|
```grain
|
|
285
|
-
|
|
368
|
+
(>) : (x: Float32, y: Float32) => Bool
|
|
286
369
|
```
|
|
287
370
|
|
|
288
371
|
Checks if the first value is greater than the second value.
|
|
@@ -300,15 +383,29 @@ Returns:
|
|
|
300
383
|
|----|-----------|
|
|
301
384
|
|`Bool`|`true` if the first value is greater than the second value or `false` otherwise|
|
|
302
385
|
|
|
303
|
-
|
|
386
|
+
Examples:
|
|
304
387
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
388
|
+
```grain
|
|
389
|
+
use Float32.{ (>) }
|
|
390
|
+
assert 2.0f > 1.0f
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Float32.**(<=)**
|
|
394
|
+
|
|
395
|
+
<details>
|
|
396
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
397
|
+
<table>
|
|
398
|
+
<thead>
|
|
399
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
400
|
+
</thead>
|
|
401
|
+
<tbody>
|
|
402
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `lte`</td></tr>
|
|
403
|
+
</tbody>
|
|
404
|
+
</table>
|
|
308
405
|
</details>
|
|
309
406
|
|
|
310
407
|
```grain
|
|
311
|
-
|
|
408
|
+
(<=) : (x: Float32, y: Float32) => Bool
|
|
312
409
|
```
|
|
313
410
|
|
|
314
411
|
Checks if the first value is less than or equal to the second value.
|
|
@@ -326,15 +423,34 @@ Returns:
|
|
|
326
423
|
|----|-----------|
|
|
327
424
|
|`Bool`|`true` if the first value is less than or equal to the second value or `false` otherwise|
|
|
328
425
|
|
|
329
|
-
|
|
426
|
+
Examples:
|
|
330
427
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
428
|
+
```grain
|
|
429
|
+
use Float32.{ (<=) }
|
|
430
|
+
assert -1.0f <= 1.0f
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
```grain
|
|
434
|
+
use Float32.{ (<=) }
|
|
435
|
+
assert -2.0f <= -2.0f
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Float32.**(>=)**
|
|
439
|
+
|
|
440
|
+
<details>
|
|
441
|
+
<summary>Added in <code>0.6.0</code></summary>
|
|
442
|
+
<table>
|
|
443
|
+
<thead>
|
|
444
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
445
|
+
</thead>
|
|
446
|
+
<tbody>
|
|
447
|
+
<tr><td><code>0.2.0</code></td><td>Originally named `gte`</td></tr>
|
|
448
|
+
</tbody>
|
|
449
|
+
</table>
|
|
334
450
|
</details>
|
|
335
451
|
|
|
336
452
|
```grain
|
|
337
|
-
|
|
453
|
+
(>=) : (x: Float32, y: Float32) => Bool
|
|
338
454
|
```
|
|
339
455
|
|
|
340
456
|
Checks if the first value is greater than or equal to the second value.
|
|
@@ -352,3 +468,15 @@ Returns:
|
|
|
352
468
|
|----|-----------|
|
|
353
469
|
|`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
|
|
354
470
|
|
|
471
|
+
Examples:
|
|
472
|
+
|
|
473
|
+
```grain
|
|
474
|
+
use Float32.{ (>=) }
|
|
475
|
+
assert 4.0f >= 1.0f
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
```grain
|
|
479
|
+
use Float32.{ (>=) }
|
|
480
|
+
assert 3.0f >= 3.0f
|
|
481
|
+
```
|
|
482
|
+
|
package/float64.gr
CHANGED
|
@@ -1,100 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Utilities for working with the Float64 type.
|
|
3
|
+
*
|
|
4
|
+
* @example from "float64" include Float64
|
|
5
|
+
*
|
|
6
|
+
* @example 5.0d
|
|
7
|
+
* @example -5.0d
|
|
8
|
+
* @example Infinityd
|
|
9
|
+
* @example NaNd
|
|
10
|
+
*
|
|
5
11
|
* @since v0.2.0
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
module Float64
|
|
14
|
+
|
|
15
|
+
from "runtime/unsafe/wasmi32" include WasmI32
|
|
16
|
+
from "runtime/unsafe/wasmf64" include WasmF64
|
|
17
|
+
use WasmF64.{ (-), (+), (*), (/), (<), (<=), (>), (>=) }
|
|
18
|
+
from "runtime/dataStructures" include DataStructures
|
|
19
|
+
use DataStructures.{ newFloat64 }
|
|
10
20
|
|
|
11
|
-
|
|
21
|
+
from "runtime/numbers" include Numbers
|
|
22
|
+
use Numbers.{
|
|
12
23
|
coerceNumberToFloat64 as fromNumber,
|
|
13
24
|
coerceFloat64ToNumber as toNumber,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @section Constants: Float64 constant values.
|
|
18
|
-
*/
|
|
25
|
+
}
|
|
19
26
|
|
|
20
27
|
/**
|
|
21
28
|
* Infinity represented as a Float64 value.
|
|
22
|
-
*
|
|
29
|
+
* This is an alternative to the `Infinityd` literal.
|
|
30
|
+
*
|
|
23
31
|
* @since v0.4.0
|
|
24
32
|
*/
|
|
25
33
|
@unsafe
|
|
26
|
-
|
|
27
|
-
let ptr = newFloat64(
|
|
28
|
-
WasmF64.reinterpretI64(
|
|
29
|
-
0b0111111111110000000000000000000000000000000000000000000000000000N
|
|
30
|
-
)
|
|
31
|
-
)
|
|
32
|
-
WasmI32.toGrain(ptr): Float64
|
|
33
|
-
}
|
|
34
|
+
provide let infinity = Infinityd
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* NaN (Not a Number) represented as a Float64 value.
|
|
37
|
-
*
|
|
38
|
+
* This is an alternative to the `NaNd` literal.
|
|
39
|
+
*
|
|
38
40
|
* @since v0.4.0
|
|
39
41
|
*/
|
|
40
42
|
@unsafe
|
|
41
|
-
|
|
42
|
-
let ptr = newFloat64(
|
|
43
|
-
WasmF64.reinterpretI64(
|
|
44
|
-
0b0111111111110000000000000000000000000000000000000000000000000001N
|
|
45
|
-
)
|
|
46
|
-
)
|
|
47
|
-
WasmI32.toGrain(ptr): Float64
|
|
48
|
-
}
|
|
43
|
+
provide let nan = NaNd
|
|
49
44
|
|
|
50
45
|
/**
|
|
51
46
|
* Pi represented as a Float64 value.
|
|
52
|
-
*
|
|
47
|
+
*
|
|
53
48
|
* @since v0.5.2
|
|
54
49
|
*/
|
|
55
|
-
|
|
50
|
+
provide let pi = 3.141592653589793d
|
|
56
51
|
|
|
57
52
|
/**
|
|
58
53
|
* Tau represented as a Float64 value.
|
|
59
|
-
*
|
|
54
|
+
*
|
|
60
55
|
* @since v0.5.2
|
|
61
56
|
*/
|
|
62
|
-
|
|
57
|
+
provide let tau = 6.283185307179586d
|
|
63
58
|
|
|
64
59
|
/**
|
|
65
60
|
* Euler's number represented as a Float64 value.
|
|
66
|
-
*
|
|
67
|
-
* @since v0.5.2
|
|
68
|
-
*/
|
|
69
|
-
export let e = 2.718281828459045d
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @section Conversions: Functions for converting between Numbers and the Float64 type.
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Converts a Number to a Float64.
|
|
77
61
|
*
|
|
78
|
-
* @
|
|
79
|
-
* @returns The Number represented as a Float64
|
|
80
|
-
*
|
|
81
|
-
* @since v0.2.0
|
|
62
|
+
* @since v0.5.2
|
|
82
63
|
*/
|
|
83
|
-
|
|
64
|
+
provide let e = 2.718281828459045d
|
|
84
65
|
|
|
85
|
-
|
|
86
|
-
* Converts a Float64 to a Number.
|
|
87
|
-
*
|
|
88
|
-
* @param float: The value to convert
|
|
89
|
-
* @returns The Float64 represented as a Number
|
|
90
|
-
*
|
|
91
|
-
* @since v0.2.0
|
|
92
|
-
*/
|
|
93
|
-
export toNumber
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @section Operations: Mathematical operations for Float64 values.
|
|
97
|
-
*/
|
|
66
|
+
provide { fromNumber, toNumber }
|
|
98
67
|
|
|
99
68
|
/**
|
|
100
69
|
* Computes the sum of its operands.
|
|
@@ -102,14 +71,19 @@ export toNumber
|
|
|
102
71
|
* @param x: The first operand
|
|
103
72
|
* @param y: The second operand
|
|
104
73
|
* @returns The sum of the two operands
|
|
105
|
-
*
|
|
106
|
-
* @
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* use Float64.{ (+) }
|
|
77
|
+
* assert 1.0d + 1.0d == 2.0d
|
|
78
|
+
*
|
|
79
|
+
* @since v0.6.0
|
|
80
|
+
* @history v0.2.0: Originally named `add`
|
|
107
81
|
*/
|
|
108
82
|
@unsafe
|
|
109
|
-
|
|
83
|
+
provide let (+) = (x: Float64, y: Float64) => {
|
|
110
84
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
111
85
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
112
|
-
let ptr = newFloat64(
|
|
86
|
+
let ptr = newFloat64(xv + yv)
|
|
113
87
|
WasmI32.toGrain(ptr): Float64
|
|
114
88
|
}
|
|
115
89
|
|
|
@@ -119,14 +93,19 @@ export let add = (x: Float64, y: Float64) => {
|
|
|
119
93
|
* @param x: The first operand
|
|
120
94
|
* @param y: The second operand
|
|
121
95
|
* @returns The difference of the two operands
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* use Float64.{ (-) }
|
|
99
|
+
* assert 5.0d - 4.0d == 1.0d
|
|
100
|
+
*
|
|
101
|
+
* @since v0.6.0
|
|
102
|
+
* @history v0.2.0: Originally named `sub`
|
|
124
103
|
*/
|
|
125
104
|
@unsafe
|
|
126
|
-
|
|
105
|
+
provide let (-) = (x: Float64, y: Float64) => {
|
|
127
106
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
128
107
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
129
|
-
let ptr = newFloat64(
|
|
108
|
+
let ptr = newFloat64(xv - yv)
|
|
130
109
|
WasmI32.toGrain(ptr): Float64
|
|
131
110
|
}
|
|
132
111
|
|
|
@@ -136,14 +115,19 @@ export let sub = (x: Float64, y: Float64) => {
|
|
|
136
115
|
* @param x: The first operand
|
|
137
116
|
* @param y: The second operand
|
|
138
117
|
* @returns The product of the two operands
|
|
139
|
-
*
|
|
140
|
-
* @
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* use Float64.{ (*) }
|
|
121
|
+
* assert -5.0d * 4.0d == -20.0d
|
|
122
|
+
*
|
|
123
|
+
* @since v0.6.0
|
|
124
|
+
* @history v0.2.0: Originally named `mul`
|
|
141
125
|
*/
|
|
142
126
|
@unsafe
|
|
143
|
-
|
|
127
|
+
provide let (*) = (x: Float64, y: Float64) => {
|
|
144
128
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
145
129
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
146
|
-
let ptr = newFloat64(
|
|
130
|
+
let ptr = newFloat64(xv * yv)
|
|
147
131
|
WasmI32.toGrain(ptr): Float64
|
|
148
132
|
}
|
|
149
133
|
|
|
@@ -153,35 +137,41 @@ export let mul = (x: Float64, y: Float64) => {
|
|
|
153
137
|
* @param x: The first operand
|
|
154
138
|
* @param y: The second operand
|
|
155
139
|
* @returns The quotient of the two operands
|
|
156
|
-
*
|
|
157
|
-
* @
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* use Float64.{ (/) }
|
|
143
|
+
* assert 25.0d / 4.0d == 6.25d
|
|
144
|
+
*
|
|
145
|
+
* @since v0.6.0
|
|
146
|
+
* @history v0.2.0: Originally named `div`
|
|
158
147
|
*/
|
|
159
148
|
@unsafe
|
|
160
|
-
|
|
149
|
+
provide let (/) = (x: Float64, y: Float64) => {
|
|
161
150
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
162
151
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
163
|
-
let ptr = newFloat64(
|
|
152
|
+
let ptr = newFloat64(xv / yv)
|
|
164
153
|
WasmI32.toGrain(ptr): Float64
|
|
165
154
|
}
|
|
166
155
|
|
|
167
|
-
/**
|
|
168
|
-
* @section Comparisons: Functions for comparing Float64 values.
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
156
|
/**
|
|
172
157
|
* Checks if the first value is less than the second value.
|
|
173
158
|
*
|
|
174
159
|
* @param x: The first value
|
|
175
160
|
* @param y: The second value
|
|
176
161
|
* @returns `true` if the first value is less than the second value or `false` otherwise
|
|
177
|
-
*
|
|
178
|
-
* @
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* use Float64.{ (<) }
|
|
165
|
+
* assert -5.0d < 5.0d
|
|
166
|
+
*
|
|
167
|
+
* @since v0.6.0
|
|
168
|
+
* @history v0.2.0: Originally named `lt`
|
|
179
169
|
*/
|
|
180
170
|
@unsafe
|
|
181
|
-
|
|
171
|
+
provide let (<) = (x: Float64, y: Float64) => {
|
|
182
172
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
183
173
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
184
|
-
|
|
174
|
+
xv < yv
|
|
185
175
|
}
|
|
186
176
|
|
|
187
177
|
/**
|
|
@@ -190,14 +180,19 @@ export let lt = (x: Float64, y: Float64) => {
|
|
|
190
180
|
* @param x: The first value
|
|
191
181
|
* @param y: The second value
|
|
192
182
|
* @returns `true` if the first value is greater than the second value or `false` otherwise
|
|
193
|
-
*
|
|
194
|
-
* @
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* use Float64.{ (>) }
|
|
186
|
+
* assert 6.0d > 5.0d
|
|
187
|
+
*
|
|
188
|
+
* @since v0.6.0
|
|
189
|
+
* @history v0.2.0: Originally named `gt`
|
|
195
190
|
*/
|
|
196
191
|
@unsafe
|
|
197
|
-
|
|
192
|
+
provide let (>) = (x: Float64, y: Float64) => {
|
|
198
193
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
199
194
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
200
|
-
|
|
195
|
+
xv > yv
|
|
201
196
|
}
|
|
202
197
|
|
|
203
198
|
/**
|
|
@@ -206,14 +201,23 @@ export let gt = (x: Float64, y: Float64) => {
|
|
|
206
201
|
* @param x: The first value
|
|
207
202
|
* @param y: The second value
|
|
208
203
|
* @returns `true` if the first value is less than or equal to the second value or `false` otherwise
|
|
209
|
-
*
|
|
210
|
-
* @
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* use Float64.{ (<=) }
|
|
207
|
+
* assert 1.0d <= 2.0d
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* use Float64.{ (<=) }
|
|
211
|
+
* assert 2.0d <= 2.0d
|
|
212
|
+
*
|
|
213
|
+
* @since v0.6.0
|
|
214
|
+
* @history v0.2.0: Originally named `lte`
|
|
211
215
|
*/
|
|
212
216
|
@unsafe
|
|
213
|
-
|
|
217
|
+
provide let (<=) = (x: Float64, y: Float64) => {
|
|
214
218
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
215
219
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
216
|
-
|
|
220
|
+
xv <= yv
|
|
217
221
|
}
|
|
218
222
|
|
|
219
223
|
/**
|
|
@@ -222,12 +226,21 @@ export let lte = (x: Float64, y: Float64) => {
|
|
|
222
226
|
* @param x: The first value
|
|
223
227
|
* @param y: The second value
|
|
224
228
|
* @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
|
|
225
|
-
*
|
|
226
|
-
* @
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* use Float64.{ (>=) }
|
|
232
|
+
* assert 5.0d >= 2.0d
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* use Float64.{ (>=) }
|
|
236
|
+
* assert -1.0d >= -1.0d
|
|
237
|
+
*
|
|
238
|
+
* @since v0.6.0
|
|
239
|
+
* @history v0.2.0: Originally named `gte`
|
|
227
240
|
*/
|
|
228
241
|
@unsafe
|
|
229
|
-
|
|
242
|
+
provide let (>=) = (x: Float64, y: Float64) => {
|
|
230
243
|
let xv = WasmF64.load(WasmI32.fromGrain(x), 8n)
|
|
231
244
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
232
|
-
|
|
245
|
+
xv >= yv
|
|
233
246
|
}
|