@grain/stdlib 0.5.1 → 0.5.2
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 +13 -0
- package/bigint.md +31 -31
- package/buffer.gr +10 -10
- package/buffer.md +1 -1
- package/bytes.md +1 -1
- package/exception.gr +28 -2
- package/exception.md +37 -0
- package/float32.gr +50 -30
- package/float32.md +69 -30
- package/float64.gr +55 -34
- package/float64.md +69 -30
- package/int32.md +4 -4
- package/int64.md +4 -4
- package/map.md +1 -1
- package/number.gr +81 -0
- package/number.md +97 -0
- package/package.json +1 -1
- package/random.md +7 -7
- package/runtime/numbers.gr +24 -18
- package/set.md +1 -1
- package/sys/random.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
### [0.5.2](https://github.com/grain-lang/grain/compare/stdlib-v0.5.1...stdlib-v0.5.2) (2022-06-29)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **stdlib:** Add number constants to number libraries ([#1331](https://github.com/grain-lang/grain/issues/1331)) ([f640ec2](https://github.com/grain-lang/grain/commit/f640ec20aa507c83c9cde290b911d0adcb4e8254))
|
|
9
|
+
* **stdlib:** Implement Number.sin and Number.cos ([#1343](https://github.com/grain-lang/grain/issues/1343)) ([9357126](https://github.com/grain-lang/grain/commit/93571267b7df53e1cb9f61eaebf8748885e7392c))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* **stdlib:** Make toNumber functions respect Number invariants ([#1347](https://github.com/grain-lang/grain/issues/1347)) ([78db882](https://github.com/grain-lang/grain/commit/78db8820cf5667a4d6737c9109f4223c1348b245))
|
|
15
|
+
|
|
3
16
|
### [0.5.1](https://github.com/grain-lang/grain/compare/stdlib-v0.5.0...stdlib-v0.5.1) (2022-06-08)
|
|
4
17
|
|
|
5
18
|
|
package/bigint.md
CHANGED
|
@@ -5,7 +5,7 @@ title: BigInt
|
|
|
5
5
|
Utilities for working with the BigInt type.
|
|
6
6
|
|
|
7
7
|
<details disabled>
|
|
8
|
-
<summary tabindex="-1">Added in <code>
|
|
8
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
9
9
|
No other changes yet.
|
|
10
10
|
</details>
|
|
11
11
|
|
|
@@ -20,7 +20,7 @@ Functions for converting between Numbers and the BigInt type.
|
|
|
20
20
|
### Bigint.**fromNumber**
|
|
21
21
|
|
|
22
22
|
<details disabled>
|
|
23
|
-
<summary tabindex="-1">Added in <code>
|
|
23
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
24
24
|
No other changes yet.
|
|
25
25
|
</details>
|
|
26
26
|
|
|
@@ -45,7 +45,7 @@ Returns:
|
|
|
45
45
|
### Bigint.**toNumber**
|
|
46
46
|
|
|
47
47
|
<details disabled>
|
|
48
|
-
<summary tabindex="-1">Added in <code>
|
|
48
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
49
49
|
No other changes yet.
|
|
50
50
|
</details>
|
|
51
51
|
|
|
@@ -74,7 +74,7 @@ Mathematical operations for BigInt values.
|
|
|
74
74
|
### Bigint.**incr**
|
|
75
75
|
|
|
76
76
|
<details disabled>
|
|
77
|
-
<summary tabindex="-1">Added in <code>
|
|
77
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
78
78
|
No other changes yet.
|
|
79
79
|
</details>
|
|
80
80
|
|
|
@@ -99,7 +99,7 @@ Returns:
|
|
|
99
99
|
### Bigint.**decr**
|
|
100
100
|
|
|
101
101
|
<details disabled>
|
|
102
|
-
<summary tabindex="-1">Added in <code>
|
|
102
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
103
103
|
No other changes yet.
|
|
104
104
|
</details>
|
|
105
105
|
|
|
@@ -124,7 +124,7 @@ Returns:
|
|
|
124
124
|
### Bigint.**neg**
|
|
125
125
|
|
|
126
126
|
<details disabled>
|
|
127
|
-
<summary tabindex="-1">Added in <code>
|
|
127
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
128
128
|
No other changes yet.
|
|
129
129
|
</details>
|
|
130
130
|
|
|
@@ -149,7 +149,7 @@ Returns:
|
|
|
149
149
|
### Bigint.**abs**
|
|
150
150
|
|
|
151
151
|
<details disabled>
|
|
152
|
-
<summary tabindex="-1">Added in <code>
|
|
152
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
153
153
|
No other changes yet.
|
|
154
154
|
</details>
|
|
155
155
|
|
|
@@ -174,7 +174,7 @@ Returns:
|
|
|
174
174
|
### Bigint.**add**
|
|
175
175
|
|
|
176
176
|
<details disabled>
|
|
177
|
-
<summary tabindex="-1">Added in <code>
|
|
177
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
178
178
|
No other changes yet.
|
|
179
179
|
</details>
|
|
180
180
|
|
|
@@ -200,7 +200,7 @@ Returns:
|
|
|
200
200
|
### Bigint.**sub**
|
|
201
201
|
|
|
202
202
|
<details disabled>
|
|
203
|
-
<summary tabindex="-1">Added in <code>
|
|
203
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
204
204
|
No other changes yet.
|
|
205
205
|
</details>
|
|
206
206
|
|
|
@@ -226,7 +226,7 @@ Returns:
|
|
|
226
226
|
### Bigint.**mul**
|
|
227
227
|
|
|
228
228
|
<details disabled>
|
|
229
|
-
<summary tabindex="-1">Added in <code>
|
|
229
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
230
230
|
No other changes yet.
|
|
231
231
|
</details>
|
|
232
232
|
|
|
@@ -252,7 +252,7 @@ Returns:
|
|
|
252
252
|
### Bigint.**div**
|
|
253
253
|
|
|
254
254
|
<details disabled>
|
|
255
|
-
<summary tabindex="-1">Added in <code>
|
|
255
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
256
256
|
No other changes yet.
|
|
257
257
|
</details>
|
|
258
258
|
|
|
@@ -279,7 +279,7 @@ Returns:
|
|
|
279
279
|
### Bigint.**rem**
|
|
280
280
|
|
|
281
281
|
<details disabled>
|
|
282
|
-
<summary tabindex="-1">Added in <code>
|
|
282
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
283
283
|
No other changes yet.
|
|
284
284
|
</details>
|
|
285
285
|
|
|
@@ -306,7 +306,7 @@ Returns:
|
|
|
306
306
|
### Bigint.**quotRem**
|
|
307
307
|
|
|
308
308
|
<details disabled>
|
|
309
|
-
<summary tabindex="-1">Added in <code>
|
|
309
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
310
310
|
No other changes yet.
|
|
311
311
|
</details>
|
|
312
312
|
|
|
@@ -332,7 +332,7 @@ Returns:
|
|
|
332
332
|
### Bigint.**gcd**
|
|
333
333
|
|
|
334
334
|
<details disabled>
|
|
335
|
-
<summary tabindex="-1">Added in <code>
|
|
335
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
336
336
|
No other changes yet.
|
|
337
337
|
</details>
|
|
338
338
|
|
|
@@ -362,7 +362,7 @@ Functions for operating on bits of BigInt values.
|
|
|
362
362
|
### Bigint.**shl**
|
|
363
363
|
|
|
364
364
|
<details disabled>
|
|
365
|
-
<summary tabindex="-1">Added in <code>
|
|
365
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
366
366
|
No other changes yet.
|
|
367
367
|
</details>
|
|
368
368
|
|
|
@@ -388,7 +388,7 @@ Returns:
|
|
|
388
388
|
### Bigint.**shr**
|
|
389
389
|
|
|
390
390
|
<details disabled>
|
|
391
|
-
<summary tabindex="-1">Added in <code>
|
|
391
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
392
392
|
No other changes yet.
|
|
393
393
|
</details>
|
|
394
394
|
|
|
@@ -418,7 +418,7 @@ Functions for comparing BigInt values.
|
|
|
418
418
|
### Bigint.**eqz**
|
|
419
419
|
|
|
420
420
|
<details disabled>
|
|
421
|
-
<summary tabindex="-1">Added in <code>
|
|
421
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
422
422
|
No other changes yet.
|
|
423
423
|
</details>
|
|
424
424
|
|
|
@@ -443,7 +443,7 @@ Returns:
|
|
|
443
443
|
### Bigint.**eq**
|
|
444
444
|
|
|
445
445
|
<details disabled>
|
|
446
|
-
<summary tabindex="-1">Added in <code>
|
|
446
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
447
447
|
No other changes yet.
|
|
448
448
|
</details>
|
|
449
449
|
|
|
@@ -469,7 +469,7 @@ Returns:
|
|
|
469
469
|
### Bigint.**ne**
|
|
470
470
|
|
|
471
471
|
<details disabled>
|
|
472
|
-
<summary tabindex="-1">Added in <code>
|
|
472
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
473
473
|
No other changes yet.
|
|
474
474
|
</details>
|
|
475
475
|
|
|
@@ -495,7 +495,7 @@ Returns:
|
|
|
495
495
|
### Bigint.**lt**
|
|
496
496
|
|
|
497
497
|
<details disabled>
|
|
498
|
-
<summary tabindex="-1">Added in <code>
|
|
498
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
499
499
|
No other changes yet.
|
|
500
500
|
</details>
|
|
501
501
|
|
|
@@ -521,7 +521,7 @@ Returns:
|
|
|
521
521
|
### Bigint.**lte**
|
|
522
522
|
|
|
523
523
|
<details disabled>
|
|
524
|
-
<summary tabindex="-1">Added in <code>
|
|
524
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
525
525
|
No other changes yet.
|
|
526
526
|
</details>
|
|
527
527
|
|
|
@@ -547,7 +547,7 @@ Returns:
|
|
|
547
547
|
### Bigint.**gt**
|
|
548
548
|
|
|
549
549
|
<details disabled>
|
|
550
|
-
<summary tabindex="-1">Added in <code>
|
|
550
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
551
551
|
No other changes yet.
|
|
552
552
|
</details>
|
|
553
553
|
|
|
@@ -573,7 +573,7 @@ Returns:
|
|
|
573
573
|
### Bigint.**gte**
|
|
574
574
|
|
|
575
575
|
<details disabled>
|
|
576
|
-
<summary tabindex="-1">Added in <code>
|
|
576
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
577
577
|
No other changes yet.
|
|
578
578
|
</details>
|
|
579
579
|
|
|
@@ -603,7 +603,7 @@ Boolean operations on the bits of BigInt values.
|
|
|
603
603
|
### Bigint.**lnot**
|
|
604
604
|
|
|
605
605
|
<details disabled>
|
|
606
|
-
<summary tabindex="-1">Added in <code>
|
|
606
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
607
607
|
No other changes yet.
|
|
608
608
|
</details>
|
|
609
609
|
|
|
@@ -628,7 +628,7 @@ Returns:
|
|
|
628
628
|
### Bigint.**land**
|
|
629
629
|
|
|
630
630
|
<details disabled>
|
|
631
|
-
<summary tabindex="-1">Added in <code>
|
|
631
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
632
632
|
No other changes yet.
|
|
633
633
|
</details>
|
|
634
634
|
|
|
@@ -654,7 +654,7 @@ Returns:
|
|
|
654
654
|
### Bigint.**lor**
|
|
655
655
|
|
|
656
656
|
<details disabled>
|
|
657
|
-
<summary tabindex="-1">Added in <code>
|
|
657
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
658
658
|
No other changes yet.
|
|
659
659
|
</details>
|
|
660
660
|
|
|
@@ -680,7 +680,7 @@ Returns:
|
|
|
680
680
|
### Bigint.**lxor**
|
|
681
681
|
|
|
682
682
|
<details disabled>
|
|
683
|
-
<summary tabindex="-1">Added in <code>
|
|
683
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
684
684
|
No other changes yet.
|
|
685
685
|
</details>
|
|
686
686
|
|
|
@@ -706,7 +706,7 @@ Returns:
|
|
|
706
706
|
### Bigint.**clz**
|
|
707
707
|
|
|
708
708
|
<details disabled>
|
|
709
|
-
<summary tabindex="-1">Added in <code>
|
|
709
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
710
710
|
No other changes yet.
|
|
711
711
|
</details>
|
|
712
712
|
|
|
@@ -732,7 +732,7 @@ Returns:
|
|
|
732
732
|
### Bigint.**ctz**
|
|
733
733
|
|
|
734
734
|
<details disabled>
|
|
735
|
-
<summary tabindex="-1">Added in <code>
|
|
735
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
736
736
|
No other changes yet.
|
|
737
737
|
</details>
|
|
738
738
|
|
|
@@ -757,7 +757,7 @@ Returns:
|
|
|
757
757
|
### Bigint.**popcnt**
|
|
758
758
|
|
|
759
759
|
<details disabled>
|
|
760
|
-
<summary tabindex="-1">Added in <code>
|
|
760
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
761
761
|
No other changes yet.
|
|
762
762
|
</details>
|
|
763
763
|
|
|
@@ -787,7 +787,7 @@ Other functions on BigInts.
|
|
|
787
787
|
### Bigint.**toString**
|
|
788
788
|
|
|
789
789
|
<details disabled>
|
|
790
|
-
<summary tabindex="-1">Added in <code>
|
|
790
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
791
791
|
No other changes yet.
|
|
792
792
|
</details>
|
|
793
793
|
|
package/buffer.gr
CHANGED
|
@@ -83,21 +83,21 @@ let checkIsIndexInBounds = (i, len, buf) => {
|
|
|
83
83
|
let addInt8help = (value, buffer) => {
|
|
84
84
|
autogrow(_8BIT_LEN, buffer)
|
|
85
85
|
let index = buffer.len
|
|
86
|
-
buffer.len
|
|
86
|
+
buffer.len += _8BIT_LEN
|
|
87
87
|
Bytes.setInt8(index, value, buffer.data)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
let addInt16help = (value, buffer) => {
|
|
91
91
|
autogrow(_16BIT_LEN, buffer)
|
|
92
92
|
let index = buffer.len
|
|
93
|
-
buffer.len
|
|
93
|
+
buffer.len += _16BIT_LEN
|
|
94
94
|
Bytes.setInt16(index, value, buffer.data)
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
let addInt32help = (value, buffer) => {
|
|
98
98
|
autogrow(_32BIT_LEN, buffer)
|
|
99
99
|
let index = buffer.len
|
|
100
|
-
buffer.len
|
|
100
|
+
buffer.len += _32BIT_LEN
|
|
101
101
|
Bytes.setInt32(index, value, buffer.data)
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -255,7 +255,7 @@ export let addBytes = (bytes, buffer) => {
|
|
|
255
255
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
256
256
|
appendBytes(0n, off, len, src, dst)
|
|
257
257
|
|
|
258
|
-
buffer.len
|
|
258
|
+
buffer.len += bytelen
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
/**
|
|
@@ -278,7 +278,7 @@ export let addString = (string, buffer) => {
|
|
|
278
278
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
279
279
|
appendBytes(0n, off, len, src, dst)
|
|
280
280
|
|
|
281
|
-
buffer.len
|
|
281
|
+
buffer.len += bytelen
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
/**
|
|
@@ -318,7 +318,7 @@ export let addStringSlice = (start: Number, end, string, buffer) => {
|
|
|
318
318
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
319
319
|
appendBytes(srcOff, dstOff, coerceNumberToWasmI32(bytelen), src, dst)
|
|
320
320
|
|
|
321
|
-
buffer.len
|
|
321
|
+
buffer.len += bytelen
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
/**
|
|
@@ -364,7 +364,7 @@ export let addBytesSlice =
|
|
|
364
364
|
let dst = WasmI32.fromGrain(buffer.data)
|
|
365
365
|
appendBytes(srcOff, dstOff, len, src, dst)
|
|
366
366
|
|
|
367
|
-
buffer.len
|
|
367
|
+
buffer.len += length
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
/**
|
|
@@ -588,7 +588,7 @@ export let setFloat32 = (index, value, buffer) => {
|
|
|
588
588
|
export let addFloat32 = (value, buffer) => {
|
|
589
589
|
autogrow(_32BIT_LEN, buffer)
|
|
590
590
|
let index = buffer.len
|
|
591
|
-
buffer.len
|
|
591
|
+
buffer.len += _32BIT_LEN
|
|
592
592
|
setFloat32(index, value, buffer)
|
|
593
593
|
}
|
|
594
594
|
|
|
@@ -631,7 +631,7 @@ export let setInt64 = (index, value, buffer) => {
|
|
|
631
631
|
export let addInt64 = (value, buffer) => {
|
|
632
632
|
autogrow(_64BIT_LEN, buffer)
|
|
633
633
|
let index = buffer.len
|
|
634
|
-
buffer.len
|
|
634
|
+
buffer.len += _64BIT_LEN
|
|
635
635
|
setInt64(index, value, buffer)
|
|
636
636
|
}
|
|
637
637
|
|
|
@@ -674,6 +674,6 @@ export let setFloat64 = (index, value, buffer) => {
|
|
|
674
674
|
export let addFloat64 = (value, buffer) => {
|
|
675
675
|
autogrow(_64BIT_LEN, buffer)
|
|
676
676
|
let index = buffer.len
|
|
677
|
-
buffer.len
|
|
677
|
+
buffer.len += _64BIT_LEN
|
|
678
678
|
setFloat64(index, value, buffer)
|
|
679
679
|
}
|
package/buffer.md
CHANGED
|
@@ -309,7 +309,7 @@ Parameters:
|
|
|
309
309
|
<tr><th>version</th><th>changes</th></tr>
|
|
310
310
|
</thead>
|
|
311
311
|
<tbody>
|
|
312
|
-
<tr><td><code>
|
|
312
|
+
<tr><td><code>0.5.0</code></td><td>Now takes the end offset instead of length</td></tr>
|
|
313
313
|
</tbody>
|
|
314
314
|
</table>
|
|
315
315
|
</details>
|
package/bytes.md
CHANGED
package/exception.gr
CHANGED
|
@@ -1,11 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module Exception: Utilities for working with the Exception type.
|
|
3
|
+
*
|
|
4
|
+
* The Exception type represents an error that has occured during computation.
|
|
5
|
+
*
|
|
6
|
+
* @example import Exception from "exception"
|
|
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 Exception from "runtime/exception"
|
|
4
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @section Values: Functions included in the Exception module.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Registers an exception printer. When an exception is thrown, all registered
|
|
21
|
+
* printers are called in order from the most recently registered printer to
|
|
22
|
+
* the least recently registered printer. The first `Some` value returned is
|
|
23
|
+
* used as the exception's string value.
|
|
24
|
+
*
|
|
25
|
+
* @param printer: The exception printer to register
|
|
26
|
+
* @since v0.3.0
|
|
27
|
+
*/
|
|
5
28
|
@disableGC
|
|
6
|
-
export let rec registerPrinter = (
|
|
29
|
+
export let rec registerPrinter = (printer: Exception -> Option<String>) => {
|
|
30
|
+
// This function _must_ be @disableGC because the printer list uses
|
|
31
|
+
// unsafe types. Not really a memory leak as this list is never collected
|
|
32
|
+
|
|
7
33
|
// no need to increment refcount on f; we just don't decRef it at the end of the function
|
|
8
|
-
Exception.printers = WasmI32.fromGrain((
|
|
34
|
+
Exception.printers = WasmI32.fromGrain((printer, Exception.printers))
|
|
9
35
|
Memory.decRef(WasmI32.fromGrain(registerPrinter))
|
|
10
36
|
void
|
|
11
37
|
}
|
package/exception.md
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Exception
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Utilities for working with the Exception type.
|
|
6
|
+
|
|
7
|
+
The Exception type represents an error that has occured during computation.
|
|
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 Exception from "exception"
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Values
|
|
19
|
+
|
|
20
|
+
Functions included in the Exception module.
|
|
21
|
+
|
|
1
22
|
### Exception.**registerPrinter**
|
|
2
23
|
|
|
24
|
+
<details disabled>
|
|
25
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
26
|
+
No other changes yet.
|
|
27
|
+
</details>
|
|
28
|
+
|
|
3
29
|
```grain
|
|
4
30
|
registerPrinter : (Exception -> Option<String>) -> Void
|
|
5
31
|
```
|
|
6
32
|
|
|
33
|
+
Registers an exception printer. When an exception is thrown, all registered
|
|
34
|
+
printers are called in order from the most recently registered printer to
|
|
35
|
+
the least recently registered printer. The first `Some` value returned is
|
|
36
|
+
used as the exception's string value.
|
|
37
|
+
|
|
38
|
+
Parameters:
|
|
39
|
+
|
|
40
|
+
|param|type|description|
|
|
41
|
+
|-----|----|-----------|
|
|
42
|
+
|`printer`|`Exception -> Option<String>`|The exception printer to register|
|
|
43
|
+
|
package/float32.gr
CHANGED
|
@@ -13,6 +13,56 @@ import {
|
|
|
13
13
|
coerceFloat32ToNumber as toNumber,
|
|
14
14
|
} from "runtime/numbers"
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @section Constants: Float32 constant values.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Infinity represented as a Float32 value.
|
|
22
|
+
*
|
|
23
|
+
* @since v0.4.0
|
|
24
|
+
*/
|
|
25
|
+
@unsafe
|
|
26
|
+
export let infinity = {
|
|
27
|
+
let ptr = newFloat32(
|
|
28
|
+
WasmF32.reinterpretI32(0b01111111100000000000000000000000n)
|
|
29
|
+
)
|
|
30
|
+
WasmI32.toGrain(ptr): Float32
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* NaN (Not a Number) represented as a Float32 value.
|
|
35
|
+
*
|
|
36
|
+
* @since v0.4.0
|
|
37
|
+
*/
|
|
38
|
+
@unsafe
|
|
39
|
+
export let nan = {
|
|
40
|
+
let ptr = newFloat32(
|
|
41
|
+
WasmF32.reinterpretI32(0b01111111100000000000000000000001n)
|
|
42
|
+
)
|
|
43
|
+
WasmI32.toGrain(ptr): Float32
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Pi represented as a Float32 value.
|
|
48
|
+
*
|
|
49
|
+
* @since v0.5.2
|
|
50
|
+
*/
|
|
51
|
+
export let pi = 3.1415927f
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Tau represented as a Float32 value.
|
|
55
|
+
*
|
|
56
|
+
* @since v0.5.2
|
|
57
|
+
*/
|
|
58
|
+
export let tau = 6.2831853f
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Euler's number represented as a Float32 value.
|
|
62
|
+
*
|
|
63
|
+
* @since v0.5.2
|
|
64
|
+
*/
|
|
65
|
+
export let e = 2.7182817f
|
|
16
66
|
/**
|
|
17
67
|
* @section Conversions: Functions for converting between Numbers and the Float32 type.
|
|
18
68
|
*/
|
|
@@ -176,33 +226,3 @@ export let gte = (x: Float32, y: Float32) => {
|
|
|
176
226
|
let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
|
|
177
227
|
WasmF32.ge(xv, yv)
|
|
178
228
|
}
|
|
179
|
-
|
|
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
|
|
195
|
-
}
|
|
196
|
-
|
|
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
|
|
208
|
-
}
|
package/float32.md
CHANGED
|
@@ -13,6 +13,75 @@ No other changes yet.
|
|
|
13
13
|
import Float32 from "float32"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
## Constants
|
|
17
|
+
|
|
18
|
+
Float32 constant values.
|
|
19
|
+
|
|
20
|
+
### Float32.**infinity**
|
|
21
|
+
|
|
22
|
+
<details disabled>
|
|
23
|
+
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
24
|
+
No other changes yet.
|
|
25
|
+
</details>
|
|
26
|
+
|
|
27
|
+
```grain
|
|
28
|
+
infinity : Float32
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Infinity represented as a Float32 value.
|
|
32
|
+
|
|
33
|
+
### Float32.**nan**
|
|
34
|
+
|
|
35
|
+
<details disabled>
|
|
36
|
+
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
37
|
+
No other changes yet.
|
|
38
|
+
</details>
|
|
39
|
+
|
|
40
|
+
```grain
|
|
41
|
+
nan : Float32
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
NaN (Not a Number) represented as a Float32 value.
|
|
45
|
+
|
|
46
|
+
### Float32.**pi**
|
|
47
|
+
|
|
48
|
+
<details disabled>
|
|
49
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
50
|
+
No other changes yet.
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
```grain
|
|
54
|
+
pi : Float32
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Pi represented as a Float32 value.
|
|
58
|
+
|
|
59
|
+
### Float32.**tau**
|
|
60
|
+
|
|
61
|
+
<details disabled>
|
|
62
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
63
|
+
No other changes yet.
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
```grain
|
|
67
|
+
tau : Float32
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Tau represented as a Float32 value.
|
|
71
|
+
|
|
72
|
+
### Float32.**e**
|
|
73
|
+
|
|
74
|
+
<details disabled>
|
|
75
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
76
|
+
No other changes yet.
|
|
77
|
+
</details>
|
|
78
|
+
|
|
79
|
+
```grain
|
|
80
|
+
e : Float32
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Euler's number represented as a Float32 value.
|
|
84
|
+
|
|
16
85
|
## Conversions
|
|
17
86
|
|
|
18
87
|
Functions for converting between Numbers and the Float32 type.
|
|
@@ -283,33 +352,3 @@ Returns:
|
|
|
283
352
|
|----|-----------|
|
|
284
353
|
|`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
|
|
285
354
|
|
|
286
|
-
## Constants
|
|
287
|
-
|
|
288
|
-
Float32 constant values.
|
|
289
|
-
|
|
290
|
-
### Float32.**infinity**
|
|
291
|
-
|
|
292
|
-
<details disabled>
|
|
293
|
-
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
294
|
-
No other changes yet.
|
|
295
|
-
</details>
|
|
296
|
-
|
|
297
|
-
```grain
|
|
298
|
-
infinity : Float32
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Infinity represented as a Float32 value.
|
|
302
|
-
|
|
303
|
-
### Float32.**nan**
|
|
304
|
-
|
|
305
|
-
<details disabled>
|
|
306
|
-
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
307
|
-
No other changes yet.
|
|
308
|
-
</details>
|
|
309
|
-
|
|
310
|
-
```grain
|
|
311
|
-
nan : Float32
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
NaN (Not a Number) represented as a Float32 value.
|
|
315
|
-
|
package/float64.gr
CHANGED
|
@@ -13,6 +13,61 @@ import {
|
|
|
13
13
|
coerceFloat64ToNumber as toNumber,
|
|
14
14
|
} from "runtime/numbers"
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* @section Constants: Float64 constant values.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Infinity represented as a Float64 value.
|
|
22
|
+
*
|
|
23
|
+
* @since v0.4.0
|
|
24
|
+
*/
|
|
25
|
+
@unsafe
|
|
26
|
+
export let infinity = {
|
|
27
|
+
let ptr = newFloat64(
|
|
28
|
+
WasmF64.reinterpretI64(
|
|
29
|
+
0b0111111111110000000000000000000000000000000000000000000000000000N
|
|
30
|
+
)
|
|
31
|
+
)
|
|
32
|
+
WasmI32.toGrain(ptr): Float64
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* NaN (Not a Number) represented as a Float64 value.
|
|
37
|
+
*
|
|
38
|
+
* @since v0.4.0
|
|
39
|
+
*/
|
|
40
|
+
@unsafe
|
|
41
|
+
export let nan = {
|
|
42
|
+
let ptr = newFloat64(
|
|
43
|
+
WasmF64.reinterpretI64(
|
|
44
|
+
0b0111111111110000000000000000000000000000000000000000000000000001N
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
WasmI32.toGrain(ptr): Float64
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Pi represented as a Float64 value.
|
|
52
|
+
*
|
|
53
|
+
* @since v0.5.2
|
|
54
|
+
*/
|
|
55
|
+
export let pi = 3.141592653589793d
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Tau represented as a Float64 value.
|
|
59
|
+
*
|
|
60
|
+
* @since v0.5.2
|
|
61
|
+
*/
|
|
62
|
+
export let tau = 6.283185307179586d
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Euler's number represented as a Float64 value.
|
|
66
|
+
*
|
|
67
|
+
* @since v0.5.2
|
|
68
|
+
*/
|
|
69
|
+
export let e = 2.718281828459045d
|
|
70
|
+
|
|
16
71
|
/**
|
|
17
72
|
* @section Conversions: Functions for converting between Numbers and the Float64 type.
|
|
18
73
|
*/
|
|
@@ -176,37 +231,3 @@ export let gte = (x: Float64, y: Float64) => {
|
|
|
176
231
|
let yv = WasmF64.load(WasmI32.fromGrain(y), 8n)
|
|
177
232
|
WasmF64.ge(xv, yv)
|
|
178
233
|
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* @section Constants: Float64 constant values.
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Infinity represented as a Float64 value.
|
|
186
|
-
*
|
|
187
|
-
* @since v0.4.0
|
|
188
|
-
*/
|
|
189
|
-
@unsafe
|
|
190
|
-
export let infinity = {
|
|
191
|
-
let ptr = newFloat64(
|
|
192
|
-
WasmF64.reinterpretI64(
|
|
193
|
-
0b0111111111110000000000000000000000000000000000000000000000000000N
|
|
194
|
-
)
|
|
195
|
-
)
|
|
196
|
-
WasmI32.toGrain(ptr): Float64
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* NaN (Not a Number) represented as a Float64 value.
|
|
201
|
-
*
|
|
202
|
-
* @since v0.4.0
|
|
203
|
-
*/
|
|
204
|
-
@unsafe
|
|
205
|
-
export let nan = {
|
|
206
|
-
let ptr = newFloat64(
|
|
207
|
-
WasmF64.reinterpretI64(
|
|
208
|
-
0b0111111111110000000000000000000000000000000000000000000000000001N
|
|
209
|
-
)
|
|
210
|
-
)
|
|
211
|
-
WasmI32.toGrain(ptr): Float64
|
|
212
|
-
}
|
package/float64.md
CHANGED
|
@@ -13,6 +13,75 @@ No other changes yet.
|
|
|
13
13
|
import Float64 from "float64"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
## Constants
|
|
17
|
+
|
|
18
|
+
Float64 constant values.
|
|
19
|
+
|
|
20
|
+
### Float64.**infinity**
|
|
21
|
+
|
|
22
|
+
<details disabled>
|
|
23
|
+
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
24
|
+
No other changes yet.
|
|
25
|
+
</details>
|
|
26
|
+
|
|
27
|
+
```grain
|
|
28
|
+
infinity : Float64
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Infinity represented as a Float64 value.
|
|
32
|
+
|
|
33
|
+
### Float64.**nan**
|
|
34
|
+
|
|
35
|
+
<details disabled>
|
|
36
|
+
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
37
|
+
No other changes yet.
|
|
38
|
+
</details>
|
|
39
|
+
|
|
40
|
+
```grain
|
|
41
|
+
nan : Float64
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
NaN (Not a Number) represented as a Float64 value.
|
|
45
|
+
|
|
46
|
+
### Float64.**pi**
|
|
47
|
+
|
|
48
|
+
<details disabled>
|
|
49
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
50
|
+
No other changes yet.
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
```grain
|
|
54
|
+
pi : Float64
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Pi represented as a Float64 value.
|
|
58
|
+
|
|
59
|
+
### Float64.**tau**
|
|
60
|
+
|
|
61
|
+
<details disabled>
|
|
62
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
63
|
+
No other changes yet.
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
```grain
|
|
67
|
+
tau : Float64
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Tau represented as a Float64 value.
|
|
71
|
+
|
|
72
|
+
### Float64.**e**
|
|
73
|
+
|
|
74
|
+
<details disabled>
|
|
75
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
76
|
+
No other changes yet.
|
|
77
|
+
</details>
|
|
78
|
+
|
|
79
|
+
```grain
|
|
80
|
+
e : Float64
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Euler's number represented as a Float64 value.
|
|
84
|
+
|
|
16
85
|
## Conversions
|
|
17
86
|
|
|
18
87
|
Functions for converting between Numbers and the Float64 type.
|
|
@@ -283,33 +352,3 @@ Returns:
|
|
|
283
352
|
|----|-----------|
|
|
284
353
|
|`Bool`|`true` if the first value is greater than or equal to the second value or `false` otherwise|
|
|
285
354
|
|
|
286
|
-
## Constants
|
|
287
|
-
|
|
288
|
-
Float64 constant values.
|
|
289
|
-
|
|
290
|
-
### Float64.**infinity**
|
|
291
|
-
|
|
292
|
-
<details disabled>
|
|
293
|
-
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
294
|
-
No other changes yet.
|
|
295
|
-
</details>
|
|
296
|
-
|
|
297
|
-
```grain
|
|
298
|
-
infinity : Float64
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
Infinity represented as a Float64 value.
|
|
302
|
-
|
|
303
|
-
### Float64.**nan**
|
|
304
|
-
|
|
305
|
-
<details disabled>
|
|
306
|
-
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
307
|
-
No other changes yet.
|
|
308
|
-
</details>
|
|
309
|
-
|
|
310
|
-
```grain
|
|
311
|
-
nan : Float64
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
NaN (Not a Number) represented as a Float64 value.
|
|
315
|
-
|
package/int32.md
CHANGED
|
@@ -574,7 +574,7 @@ Returns:
|
|
|
574
574
|
### Int32.**ltU**
|
|
575
575
|
|
|
576
576
|
<details disabled>
|
|
577
|
-
<summary tabindex="-1">Added in <code>
|
|
577
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
578
578
|
No other changes yet.
|
|
579
579
|
</details>
|
|
580
580
|
|
|
@@ -626,7 +626,7 @@ Returns:
|
|
|
626
626
|
### Int32.**gtU**
|
|
627
627
|
|
|
628
628
|
<details disabled>
|
|
629
|
-
<summary tabindex="-1">Added in <code>
|
|
629
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
630
630
|
No other changes yet.
|
|
631
631
|
</details>
|
|
632
632
|
|
|
@@ -678,7 +678,7 @@ Returns:
|
|
|
678
678
|
### Int32.**lteU**
|
|
679
679
|
|
|
680
680
|
<details disabled>
|
|
681
|
-
<summary tabindex="-1">Added in <code>
|
|
681
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
682
682
|
No other changes yet.
|
|
683
683
|
</details>
|
|
684
684
|
|
|
@@ -730,7 +730,7 @@ Returns:
|
|
|
730
730
|
### Int32.**gteU**
|
|
731
731
|
|
|
732
732
|
<details disabled>
|
|
733
|
-
<summary tabindex="-1">Added in <code>
|
|
733
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
734
734
|
No other changes yet.
|
|
735
735
|
</details>
|
|
736
736
|
|
package/int64.md
CHANGED
|
@@ -574,7 +574,7 @@ Returns:
|
|
|
574
574
|
### Int64.**ltU**
|
|
575
575
|
|
|
576
576
|
<details disabled>
|
|
577
|
-
<summary tabindex="-1">Added in <code>
|
|
577
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
578
578
|
No other changes yet.
|
|
579
579
|
</details>
|
|
580
580
|
|
|
@@ -626,7 +626,7 @@ Returns:
|
|
|
626
626
|
### Int64.**gtU**
|
|
627
627
|
|
|
628
628
|
<details disabled>
|
|
629
|
-
<summary tabindex="-1">Added in <code>
|
|
629
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
630
630
|
No other changes yet.
|
|
631
631
|
</details>
|
|
632
632
|
|
|
@@ -678,7 +678,7 @@ Returns:
|
|
|
678
678
|
### Int64.**lteU**
|
|
679
679
|
|
|
680
680
|
<details disabled>
|
|
681
|
-
<summary tabindex="-1">Added in <code>
|
|
681
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
682
682
|
No other changes yet.
|
|
683
683
|
</details>
|
|
684
684
|
|
|
@@ -730,7 +730,7 @@ Returns:
|
|
|
730
730
|
### Int64.**gteU**
|
|
731
731
|
|
|
732
732
|
<details disabled>
|
|
733
|
-
<summary tabindex="-1">Added in <code>
|
|
733
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
734
734
|
No other changes yet.
|
|
735
735
|
</details>
|
|
736
736
|
|
package/map.md
CHANGED
|
@@ -263,7 +263,7 @@ Parameters:
|
|
|
263
263
|
<tr><th>version</th><th>changes</th></tr>
|
|
264
264
|
</thead>
|
|
265
265
|
<tbody>
|
|
266
|
-
<tr><td><code>
|
|
266
|
+
<tr><td><code>0.5.0</code></td><td>Ensured the iterator function return type is always `Void`</td></tr>
|
|
267
267
|
</tbody>
|
|
268
268
|
</table>
|
|
269
269
|
</details>
|
package/number.gr
CHANGED
|
@@ -19,6 +19,35 @@ import { parseInt } from "runtime/stringUtils"
|
|
|
19
19
|
import { newFloat64, newInt64 } from "runtime/dataStructures"
|
|
20
20
|
import Tags from "runtime/unsafe/tags"
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* @section Constants: Number constant values.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Pi represented as a Number value.
|
|
28
|
+
*
|
|
29
|
+
* @since v0.5.2
|
|
30
|
+
*/
|
|
31
|
+
export let pi = 3.141592653589793
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Tau represented as a Number value.
|
|
35
|
+
*
|
|
36
|
+
* @since v0.5.2
|
|
37
|
+
*/
|
|
38
|
+
export let tau = 6.283185307179586
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Euler's number represented as a Number value.
|
|
42
|
+
*
|
|
43
|
+
* @since v0.5.2
|
|
44
|
+
*/
|
|
45
|
+
export let e = 2.718281828459045
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @section Operations: Functions for operating on values of the Number type.
|
|
49
|
+
*/
|
|
50
|
+
|
|
22
51
|
/**
|
|
23
52
|
* Computes the sum of its operands.
|
|
24
53
|
*
|
|
@@ -317,3 +346,55 @@ export let isInfinite = (x: Number) => {
|
|
|
317
346
|
* @since v0.4.5
|
|
318
347
|
*/
|
|
319
348
|
export parseInt
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Computes how many times pi has to be subtracted to achieve the required bounds for sin.
|
|
352
|
+
*/
|
|
353
|
+
let reduceToPiBound = (radians: Number) => {
|
|
354
|
+
floor(radians / pi)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Computes the sine of a number using Chebyshev polynomials. Requires the input to be bounded to (-pi, pi). More information on the algorithm can be found here: http://mooooo.ooo/chebyshev-sine-approximation/.
|
|
359
|
+
*/
|
|
360
|
+
let chebyshevSine = (radians: Number) => {
|
|
361
|
+
let pi_minor = -0.00000008742278
|
|
362
|
+
let x2 = radians * radians
|
|
363
|
+
let p11 = 0.00000000013291342
|
|
364
|
+
let p9 = p11 * x2 + -0.000000023317787
|
|
365
|
+
let p7 = p9 * x2 + 0.0000025222919
|
|
366
|
+
let p5 = p7 * x2 + -0.00017350505
|
|
367
|
+
let p3 = p5 * x2 + 0.0066208798
|
|
368
|
+
let p1 = p3 * x2 + -0.10132118
|
|
369
|
+
(radians - pi - pi_minor) * (radians + pi + pi_minor) * p1 * radians
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Computes the sine of a number (in radians) using Chebyshev polynomials.
|
|
374
|
+
*
|
|
375
|
+
* @param radians: The input in radians
|
|
376
|
+
* @returns The computed sine
|
|
377
|
+
*
|
|
378
|
+
* @since v0.5.2
|
|
379
|
+
*/
|
|
380
|
+
export let sin = (radians: Number) => {
|
|
381
|
+
let quot = reduceToPiBound(radians)
|
|
382
|
+
let bounded = radians - pi * quot
|
|
383
|
+
if (quot % 2 == 0) {
|
|
384
|
+
chebyshevSine(bounded)
|
|
385
|
+
} else {
|
|
386
|
+
neg(chebyshevSine(bounded))
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Computes the cosine of a number (in radians) using Chebyshev polynomials.
|
|
392
|
+
*
|
|
393
|
+
* @param radians: The input in radians
|
|
394
|
+
* @returns The computed cosine
|
|
395
|
+
*
|
|
396
|
+
* @since v0.5.2
|
|
397
|
+
*/
|
|
398
|
+
export let cos = (radians: Number) => {
|
|
399
|
+
sin(pi / 2 + radians)
|
|
400
|
+
}
|
package/number.md
CHANGED
|
@@ -13,6 +13,53 @@ No other changes yet.
|
|
|
13
13
|
import Number from "number"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
## Constants
|
|
17
|
+
|
|
18
|
+
Number constant values.
|
|
19
|
+
|
|
20
|
+
### Number.**pi**
|
|
21
|
+
|
|
22
|
+
<details disabled>
|
|
23
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
24
|
+
No other changes yet.
|
|
25
|
+
</details>
|
|
26
|
+
|
|
27
|
+
```grain
|
|
28
|
+
pi : Number
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Pi represented as a Number value.
|
|
32
|
+
|
|
33
|
+
### Number.**tau**
|
|
34
|
+
|
|
35
|
+
<details disabled>
|
|
36
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
37
|
+
No other changes yet.
|
|
38
|
+
</details>
|
|
39
|
+
|
|
40
|
+
```grain
|
|
41
|
+
tau : Number
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Tau represented as a Number value.
|
|
45
|
+
|
|
46
|
+
### Number.**e**
|
|
47
|
+
|
|
48
|
+
<details disabled>
|
|
49
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
50
|
+
No other changes yet.
|
|
51
|
+
</details>
|
|
52
|
+
|
|
53
|
+
```grain
|
|
54
|
+
e : Number
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Euler's number represented as a Number value.
|
|
58
|
+
|
|
59
|
+
## Operations
|
|
60
|
+
|
|
61
|
+
Functions for operating on values of the Number type.
|
|
62
|
+
|
|
16
63
|
### Number.**add**
|
|
17
64
|
|
|
18
65
|
<details disabled>
|
|
@@ -488,3 +535,53 @@ Returns:
|
|
|
488
535
|
|----|-----------|
|
|
489
536
|
|`Result<Number, String>`|`Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise|
|
|
490
537
|
|
|
538
|
+
### Number.**sin**
|
|
539
|
+
|
|
540
|
+
<details disabled>
|
|
541
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
542
|
+
No other changes yet.
|
|
543
|
+
</details>
|
|
544
|
+
|
|
545
|
+
```grain
|
|
546
|
+
sin : Number -> Number
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
Computes the sine of a number (in radians) using Chebyshev polynomials.
|
|
550
|
+
|
|
551
|
+
Parameters:
|
|
552
|
+
|
|
553
|
+
|param|type|description|
|
|
554
|
+
|-----|----|-----------|
|
|
555
|
+
|`radians`|`Number`|The input in radians|
|
|
556
|
+
|
|
557
|
+
Returns:
|
|
558
|
+
|
|
559
|
+
|type|description|
|
|
560
|
+
|----|-----------|
|
|
561
|
+
|`Number`|The computed sine|
|
|
562
|
+
|
|
563
|
+
### Number.**cos**
|
|
564
|
+
|
|
565
|
+
<details disabled>
|
|
566
|
+
<summary tabindex="-1">Added in <code>next</code></summary>
|
|
567
|
+
No other changes yet.
|
|
568
|
+
</details>
|
|
569
|
+
|
|
570
|
+
```grain
|
|
571
|
+
cos : Number -> Number
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
Computes the cosine of a number (in radians) using Chebyshev polynomials.
|
|
575
|
+
|
|
576
|
+
Parameters:
|
|
577
|
+
|
|
578
|
+
|param|type|description|
|
|
579
|
+
|-----|----|-----------|
|
|
580
|
+
|`radians`|`Number`|The input in radians|
|
|
581
|
+
|
|
582
|
+
Returns:
|
|
583
|
+
|
|
584
|
+
|type|description|
|
|
585
|
+
|----|-----------|
|
|
586
|
+
|`Number`|The computed cosine|
|
|
587
|
+
|
package/package.json
CHANGED
package/random.md
CHANGED
|
@@ -5,7 +5,7 @@ title: Random
|
|
|
5
5
|
Pseudo-random number generation.
|
|
6
6
|
|
|
7
7
|
<details disabled>
|
|
8
|
-
<summary tabindex="-1">Added in <code>
|
|
8
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
9
9
|
No other changes yet.
|
|
10
10
|
</details>
|
|
11
11
|
|
|
@@ -30,7 +30,7 @@ Functions for working with pseudo-random number generators.
|
|
|
30
30
|
### Random.**make**
|
|
31
31
|
|
|
32
32
|
<details disabled>
|
|
33
|
-
<summary tabindex="-1">Added in <code>
|
|
33
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
34
34
|
No other changes yet.
|
|
35
35
|
</details>
|
|
36
36
|
|
|
@@ -55,7 +55,7 @@ Returns:
|
|
|
55
55
|
### Random.**makeUnseeded**
|
|
56
56
|
|
|
57
57
|
<details disabled>
|
|
58
|
-
<summary tabindex="-1">Added in <code>
|
|
58
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
59
59
|
No other changes yet.
|
|
60
60
|
</details>
|
|
61
61
|
|
|
@@ -74,7 +74,7 @@ Returns:
|
|
|
74
74
|
### Random.**nextInt32**
|
|
75
75
|
|
|
76
76
|
<details disabled>
|
|
77
|
-
<summary tabindex="-1">Added in <code>
|
|
77
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
78
78
|
No other changes yet.
|
|
79
79
|
</details>
|
|
80
80
|
|
|
@@ -99,7 +99,7 @@ Returns:
|
|
|
99
99
|
### Random.**nextInt64**
|
|
100
100
|
|
|
101
101
|
<details disabled>
|
|
102
|
-
<summary tabindex="-1">Added in <code>
|
|
102
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
103
103
|
No other changes yet.
|
|
104
104
|
</details>
|
|
105
105
|
|
|
@@ -124,7 +124,7 @@ Returns:
|
|
|
124
124
|
### Random.**nextInt32InRange**
|
|
125
125
|
|
|
126
126
|
<details disabled>
|
|
127
|
-
<summary tabindex="-1">Added in <code>
|
|
127
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
128
128
|
No other changes yet.
|
|
129
129
|
</details>
|
|
130
130
|
|
|
@@ -152,7 +152,7 @@ Returns:
|
|
|
152
152
|
### Random.**nextInt64InRange**
|
|
153
153
|
|
|
154
154
|
<details disabled>
|
|
155
|
-
<summary tabindex="-1">Added in <code>
|
|
155
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
156
156
|
No other changes yet.
|
|
157
157
|
</details>
|
|
158
158
|
|
package/runtime/numbers.gr
CHANGED
|
@@ -2070,42 +2070,48 @@ export let coerceNumberToFloat64 = (x: Number) => {
|
|
|
2070
2070
|
|
|
2071
2071
|
@unsafe
|
|
2072
2072
|
export let coerceInt32ToNumber = (x: Int32) => {
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
WasmI32.toGrain(x): Number
|
|
2073
|
+
WasmI32.toGrain(
|
|
2074
|
+
reducedInteger(WasmI64.extendI32S(boxedInt32Number(WasmI32.fromGrain(x))))
|
|
2075
|
+
): Number
|
|
2077
2076
|
}
|
|
2078
2077
|
|
|
2079
2078
|
@unsafe
|
|
2080
2079
|
export let coerceInt64ToNumber = (x: Int64) => {
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
WasmI32.toGrain(x): Number
|
|
2080
|
+
WasmI32.toGrain(
|
|
2081
|
+
reducedInteger(boxedInt64Number(WasmI32.fromGrain(x)))
|
|
2082
|
+
): Number
|
|
2085
2083
|
}
|
|
2086
2084
|
|
|
2087
2085
|
@unsafe
|
|
2088
2086
|
export let coerceBigIntToNumber = (x: BigInt) => {
|
|
2089
2087
|
let x = WasmI32.fromGrain(x)
|
|
2090
|
-
//
|
|
2088
|
+
// reducedBigInteger assumes that the bigint is dead,
|
|
2089
|
+
// but in our case, it is not
|
|
2091
2090
|
Memory.incRef(x)
|
|
2092
|
-
WasmI32.toGrain(x): Number
|
|
2091
|
+
WasmI32.toGrain(reducedBigInteger(x)): Number
|
|
2093
2092
|
}
|
|
2094
2093
|
|
|
2095
2094
|
@unsafe
|
|
2096
2095
|
export let coerceRationalToNumber = (x: Rational) => {
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2096
|
+
if (WasmI32.eq(boxedRationalDenominator(WasmI32.fromGrain(x)), 1n)) {
|
|
2097
|
+
WasmI32.toGrain(
|
|
2098
|
+
reducedInteger(
|
|
2099
|
+
WasmI64.extendI32S(boxedRationalNumerator(WasmI32.fromGrain(x)))
|
|
2100
|
+
)
|
|
2101
|
+
): Number
|
|
2102
|
+
} else {
|
|
2103
|
+
let x = WasmI32.fromGrain(x)
|
|
2104
|
+
// incRef x to reuse it via WasmI32.toGrain
|
|
2105
|
+
Memory.incRef(x)
|
|
2106
|
+
WasmI32.toGrain(x): Number
|
|
2107
|
+
}
|
|
2101
2108
|
}
|
|
2102
2109
|
|
|
2103
2110
|
@unsafe
|
|
2104
2111
|
export let coerceFloat32ToNumber = (x: Float32) => {
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
WasmI32.toGrain(x): Number
|
|
2112
|
+
WasmI32.toGrain(
|
|
2113
|
+
newFloat64(WasmF64.promoteF32(boxedFloat32Number(WasmI32.fromGrain(x))))
|
|
2114
|
+
): Number
|
|
2109
2115
|
}
|
|
2110
2116
|
|
|
2111
2117
|
@unsafe
|
package/set.md
CHANGED
|
@@ -215,7 +215,7 @@ Parameters:
|
|
|
215
215
|
<tr><th>version</th><th>changes</th></tr>
|
|
216
216
|
</thead>
|
|
217
217
|
<tbody>
|
|
218
|
-
<tr><td><code>
|
|
218
|
+
<tr><td><code>0.5.0</code></td><td>Ensured the iterator function return type is always `Void`</td></tr>
|
|
219
219
|
</tbody>
|
|
220
220
|
</table>
|
|
221
221
|
</details>
|
package/sys/random.md
CHANGED
|
@@ -15,7 +15,7 @@ Functions and constants included in the Sys/Random module.
|
|
|
15
15
|
### Random.**randomInt32**
|
|
16
16
|
|
|
17
17
|
<details disabled>
|
|
18
|
-
<summary tabindex="-1">Added in <code>
|
|
18
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
19
19
|
No other changes yet.
|
|
20
20
|
</details>
|
|
21
21
|
|
|
@@ -34,7 +34,7 @@ Returns:
|
|
|
34
34
|
### Random.**randomInt64**
|
|
35
35
|
|
|
36
36
|
<details disabled>
|
|
37
|
-
<summary tabindex="-1">Added in <code>
|
|
37
|
+
<summary tabindex="-1">Added in <code>0.5.0</code></summary>
|
|
38
38
|
No other changes yet.
|
|
39
39
|
</details>
|
|
40
40
|
|