@grain/stdlib 0.6.6 → 0.7.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.
Files changed (137) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE +1 -1
  3. package/README.md +2 -2
  4. package/array.gr +55 -7
  5. package/array.md +123 -77
  6. package/bigint.md +30 -30
  7. package/buffer.gr +20 -53
  8. package/buffer.md +47 -47
  9. package/bytes.gr +111 -35
  10. package/bytes.md +111 -32
  11. package/char.gr +201 -99
  12. package/char.md +361 -34
  13. package/exception.gr +11 -11
  14. package/exception.md +26 -1
  15. package/float32.gr +327 -3
  16. package/float32.md +606 -19
  17. package/float64.gr +320 -3
  18. package/float64.md +606 -19
  19. package/fs.gr +1082 -0
  20. package/fs.md +630 -0
  21. package/hash.gr +142 -88
  22. package/hash.md +102 -14
  23. package/int16.md +23 -23
  24. package/int32.gr +25 -4
  25. package/int32.md +65 -30
  26. package/int64.gr +26 -1
  27. package/int64.md +65 -30
  28. package/int8.md +23 -23
  29. package/json.gr +366 -51
  30. package/json.md +418 -2
  31. package/list.gr +328 -31
  32. package/list.md +492 -69
  33. package/map.gr +20 -12
  34. package/map.md +44 -38
  35. package/marshal.gr +41 -40
  36. package/marshal.md +2 -2
  37. package/number.gr +159 -30
  38. package/number.md +215 -38
  39. package/option.md +21 -21
  40. package/package.json +5 -3
  41. package/path.gr +48 -0
  42. package/path.md +103 -12
  43. package/pervasives.gr +2 -2
  44. package/pervasives.md +37 -37
  45. package/priorityqueue.gr +7 -7
  46. package/priorityqueue.md +19 -19
  47. package/queue.gr +183 -29
  48. package/queue.md +296 -40
  49. package/random.md +6 -6
  50. package/range.gr +4 -4
  51. package/range.md +6 -6
  52. package/rational.md +16 -16
  53. package/regex.gr +52 -51
  54. package/regex.md +11 -11
  55. package/result.md +16 -16
  56. package/runtime/atof/common.md +39 -39
  57. package/runtime/atof/decimal.gr +6 -6
  58. package/runtime/atof/decimal.md +8 -8
  59. package/runtime/atof/lemire.gr +5 -5
  60. package/runtime/atof/lemire.md +1 -1
  61. package/runtime/atof/parse.gr +16 -16
  62. package/runtime/atof/parse.md +2 -2
  63. package/runtime/atof/slow.md +1 -1
  64. package/runtime/atof/table.md +2 -2
  65. package/runtime/atoi/parse.gr +3 -3
  66. package/runtime/atoi/parse.md +1 -1
  67. package/runtime/bigint.gr +15 -47
  68. package/runtime/bigint.md +54 -60
  69. package/runtime/compare.gr +2 -2
  70. package/runtime/compare.md +1 -1
  71. package/runtime/dataStructures.md +33 -33
  72. package/runtime/debugPrint.gr +4 -1
  73. package/runtime/debugPrint.md +9 -9
  74. package/runtime/equal.gr +99 -77
  75. package/runtime/equal.md +1 -1
  76. package/runtime/exception.gr +62 -82
  77. package/runtime/exception.md +62 -11
  78. package/runtime/gc.gr +39 -45
  79. package/runtime/gc.md +4 -4
  80. package/runtime/malloc.gr +7 -7
  81. package/runtime/malloc.md +4 -4
  82. package/runtime/math/kernel/cos.gr +70 -0
  83. package/runtime/math/kernel/cos.md +14 -0
  84. package/runtime/math/kernel/sin.gr +65 -0
  85. package/runtime/math/kernel/sin.md +14 -0
  86. package/runtime/math/kernel/tan.gr +136 -0
  87. package/runtime/math/kernel/tan.md +14 -0
  88. package/runtime/math/rempio2.gr +244 -0
  89. package/runtime/math/rempio2.md +14 -0
  90. package/runtime/math/trig.gr +130 -0
  91. package/runtime/math/trig.md +28 -0
  92. package/runtime/math/umuldi.gr +26 -0
  93. package/runtime/math/umuldi.md +14 -0
  94. package/runtime/numberUtils.gr +29 -29
  95. package/runtime/numberUtils.md +12 -12
  96. package/runtime/numbers.gr +373 -381
  97. package/runtime/numbers.md +79 -73
  98. package/runtime/string.gr +37 -105
  99. package/runtime/string.md +3 -9
  100. package/runtime/unsafe/constants.md +24 -24
  101. package/runtime/unsafe/conv.md +13 -13
  102. package/runtime/unsafe/memory.gr +24 -20
  103. package/runtime/unsafe/memory.md +27 -7
  104. package/runtime/unsafe/offsets.gr +36 -0
  105. package/runtime/unsafe/offsets.md +88 -0
  106. package/runtime/unsafe/panic.gr +28 -0
  107. package/runtime/unsafe/panic.md +14 -0
  108. package/runtime/unsafe/tags.md +32 -32
  109. package/runtime/unsafe/wasmf32.md +28 -28
  110. package/runtime/unsafe/wasmf64.md +28 -28
  111. package/runtime/unsafe/wasmi32.md +47 -47
  112. package/runtime/unsafe/wasmi64.md +50 -50
  113. package/runtime/utf8.gr +189 -0
  114. package/runtime/utf8.md +117 -0
  115. package/runtime/wasi.gr +4 -2
  116. package/runtime/wasi.md +138 -138
  117. package/set.gr +18 -11
  118. package/set.md +42 -36
  119. package/stack.gr +171 -2
  120. package/stack.md +297 -15
  121. package/string.gr +352 -557
  122. package/string.md +77 -34
  123. package/uint16.md +22 -22
  124. package/uint32.gr +25 -4
  125. package/uint32.md +63 -28
  126. package/uint64.gr +25 -5
  127. package/uint64.md +63 -28
  128. package/uint8.md +22 -22
  129. package/uri.gr +57 -53
  130. package/uri.md +11 -12
  131. package/wasi/file.gr +67 -59
  132. package/wasi/file.md +39 -39
  133. package/wasi/process.md +5 -5
  134. package/wasi/random.md +3 -3
  135. package/wasi/time.md +4 -4
  136. package/runtime/utils/printing.gr +0 -60
  137. package/runtime/utils/printing.md +0 -26
package/int16.md CHANGED
@@ -33,7 +33,7 @@ No other changes yet.
33
33
  </details>
34
34
 
35
35
  ```grain
36
- fromNumber : (number: Number) => Int16
36
+ fromNumber: (number: Number) => Int16
37
37
  ```
38
38
 
39
39
  Converts a Number to an Int16.
@@ -58,7 +58,7 @@ No other changes yet.
58
58
  </details>
59
59
 
60
60
  ```grain
61
- toNumber : (value: Int16) => Number
61
+ toNumber: (value: Int16) => Number
62
62
  ```
63
63
 
64
64
  Converts an Int16 to a Number.
@@ -83,7 +83,7 @@ No other changes yet.
83
83
  </details>
84
84
 
85
85
  ```grain
86
- fromUint16 : (number: Uint16) => Int16
86
+ fromUint16: (number: Uint16) => Int16
87
87
  ```
88
88
 
89
89
  Converts a Uint16 to an Int16.
@@ -114,7 +114,7 @@ No other changes yet.
114
114
  </details>
115
115
 
116
116
  ```grain
117
- incr : (value: Int16) => Int16
117
+ incr: (value: Int16) => Int16
118
118
  ```
119
119
 
120
120
  Increments the value by one.
@@ -149,7 +149,7 @@ No other changes yet.
149
149
  </details>
150
150
 
151
151
  ```grain
152
- decr : (value: Int16) => Int16
152
+ decr: (value: Int16) => Int16
153
153
  ```
154
154
 
155
155
  Decrements the value by one.
@@ -184,7 +184,7 @@ No other changes yet.
184
184
  </details>
185
185
 
186
186
  ```grain
187
- (+) : (x: Int16, y: Int16) => Int16
187
+ (+): (x: Int16, y: Int16) => Int16
188
188
  ```
189
189
 
190
190
  Computes the sum of its operands.
@@ -217,7 +217,7 @@ No other changes yet.
217
217
  </details>
218
218
 
219
219
  ```grain
220
- (-) : (x: Int16, y: Int16) => Int16
220
+ (-): (x: Int16, y: Int16) => Int16
221
221
  ```
222
222
 
223
223
  Computes the difference of its operands.
@@ -250,7 +250,7 @@ No other changes yet.
250
250
  </details>
251
251
 
252
252
  ```grain
253
- (*) : (x: Int16, y: Int16) => Int16
253
+ (*): (x: Int16, y: Int16) => Int16
254
254
  ```
255
255
 
256
256
  Computes the product of its operands.
@@ -283,7 +283,7 @@ No other changes yet.
283
283
  </details>
284
284
 
285
285
  ```grain
286
- (/) : (x: Int16, y: Int16) => Int16
286
+ (/): (x: Int16, y: Int16) => Int16
287
287
  ```
288
288
 
289
289
  Computes the quotient of its operands using signed division.
@@ -316,7 +316,7 @@ No other changes yet.
316
316
  </details>
317
317
 
318
318
  ```grain
319
- rem : (x: Int16, y: Int16) => Int16
319
+ rem: (x: Int16, y: Int16) => Int16
320
320
  ```
321
321
 
322
322
  Computes the remainder of the division of its operands using signed division.
@@ -348,7 +348,7 @@ No other changes yet.
348
348
  </details>
349
349
 
350
350
  ```grain
351
- (%) : (x: Int16, y: Int16) => Int16
351
+ (%): (x: Int16, y: Int16) => Int16
352
352
  ```
353
353
 
354
354
  Computes the remainder of the division of the first operand by the second.
@@ -388,7 +388,7 @@ No other changes yet.
388
388
  </details>
389
389
 
390
390
  ```grain
391
- (<<) : (value: Int16, amount: Int16) => Int16
391
+ (<<): (value: Int16, amount: Int16) => Int16
392
392
  ```
393
393
 
394
394
  Shifts the bits of the value left by the given number of bits.
@@ -421,7 +421,7 @@ No other changes yet.
421
421
  </details>
422
422
 
423
423
  ```grain
424
- (>>) : (value: Int16, amount: Int16) => Int16
424
+ (>>): (value: Int16, amount: Int16) => Int16
425
425
  ```
426
426
 
427
427
  Shifts the bits of the value right by the given number of bits, preserving the sign bit.
@@ -454,7 +454,7 @@ No other changes yet.
454
454
  </details>
455
455
 
456
456
  ```grain
457
- (==) : (x: Int16, y: Int16) => Bool
457
+ (==): (x: Int16, y: Int16) => Bool
458
458
  ```
459
459
 
460
460
  Checks if the first value is equal to the second value.
@@ -487,7 +487,7 @@ No other changes yet.
487
487
  </details>
488
488
 
489
489
  ```grain
490
- (!=) : (x: Int16, y: Int16) => Bool
490
+ (!=): (x: Int16, y: Int16) => Bool
491
491
  ```
492
492
 
493
493
  Checks if the first value is not equal to the second value.
@@ -520,7 +520,7 @@ No other changes yet.
520
520
  </details>
521
521
 
522
522
  ```grain
523
- (<) : (x: Int16, y: Int16) => Bool
523
+ (<): (x: Int16, y: Int16) => Bool
524
524
  ```
525
525
 
526
526
  Checks if the first value is less than the second value.
@@ -553,7 +553,7 @@ No other changes yet.
553
553
  </details>
554
554
 
555
555
  ```grain
556
- (>) : (x: Int16, y: Int16) => Bool
556
+ (>): (x: Int16, y: Int16) => Bool
557
557
  ```
558
558
 
559
559
  Checks if the first value is greater than the second value.
@@ -586,7 +586,7 @@ No other changes yet.
586
586
  </details>
587
587
 
588
588
  ```grain
589
- (<=) : (x: Int16, y: Int16) => Bool
589
+ (<=): (x: Int16, y: Int16) => Bool
590
590
  ```
591
591
 
592
592
  Checks if the first value is less than or equal to the second value.
@@ -624,7 +624,7 @@ No other changes yet.
624
624
  </details>
625
625
 
626
626
  ```grain
627
- (>=) : (x: Int16, y: Int16) => Bool
627
+ (>=): (x: Int16, y: Int16) => Bool
628
628
  ```
629
629
 
630
630
  Checks if the first value is greater than or equal to the second value.
@@ -662,7 +662,7 @@ No other changes yet.
662
662
  </details>
663
663
 
664
664
  ```grain
665
- lnot : (value: Int16) => Int16
665
+ lnot: (value: Int16) => Int16
666
666
  ```
667
667
 
668
668
  Computes the bitwise NOT of the given value.
@@ -693,7 +693,7 @@ No other changes yet.
693
693
  </details>
694
694
 
695
695
  ```grain
696
- (&) : (x: Int16, y: Int16) => Int16
696
+ (&): (x: Int16, y: Int16) => Int16
697
697
  ```
698
698
 
699
699
  Computes the bitwise AND (`&`) on the given operands.
@@ -726,7 +726,7 @@ No other changes yet.
726
726
  </details>
727
727
 
728
728
  ```grain
729
- (|) : (x: Int16, y: Int16) => Int16
729
+ (|): (x: Int16, y: Int16) => Int16
730
730
  ```
731
731
 
732
732
  Computes the bitwise OR (`|`) on the given operands.
@@ -759,7 +759,7 @@ No other changes yet.
759
759
  </details>
760
760
 
761
761
  ```grain
762
- (^) : (x: Int16, y: Int16) => Int16
762
+ (^): (x: Int16, y: Int16) => Int16
763
763
  ```
764
764
 
765
765
  Computes the bitwise XOR (`^`) on the given operands.
package/int32.gr CHANGED
@@ -10,6 +10,12 @@
10
10
  */
11
11
  module Int32
12
12
 
13
+ from "runtime/unsafe/offsets" include Offsets
14
+ use Offsets.{
15
+ _UINT32_VALUE_OFFSET as _VALUE_OFFSET,
16
+ _UINT32_VALUE_OFFSET,
17
+ _FLOAT32_VALUE_OFFSET,
18
+ }
13
19
  from "runtime/unsafe/wasmi32" include WasmI32
14
20
  use WasmI32.{
15
21
  (+),
@@ -40,9 +46,6 @@ use Numbers.{
40
46
  coerceInt32ToNumber as toNumber,
41
47
  }
42
48
 
43
- @unsafe
44
- let _VALUE_OFFSET = 4n
45
-
46
49
  provide { fromNumber, toNumber }
47
50
 
48
51
  /**
@@ -57,7 +60,25 @@ provide { fromNumber, toNumber }
57
60
  */
58
61
  @unsafe
59
62
  provide let fromUint32 = (number: Uint32) => {
60
- let x = WasmI32.load(WasmI32.fromGrain(number), _VALUE_OFFSET)
63
+ let x = WasmI32.load(WasmI32.fromGrain(number), _UINT32_VALUE_OFFSET)
64
+ let result = newInt32(x)
65
+ WasmI32.toGrain(result): Int32
66
+ }
67
+
68
+ /**
69
+ * Interprets a Float32 as an Int32.
70
+ *
71
+ * @param value: The value to convert
72
+ * @returns The Float32 interpreted as an Int32
73
+ *
74
+ * @example Int32.reinterpretFloat32(1.0f) == 1065353216l
75
+ * @example Int32.reinterpretFloat32(-1.0f) == -1065353216l
76
+ *
77
+ * @since v0.7.0
78
+ */
79
+ @unsafe
80
+ provide let reinterpretFloat32 = (value: Float32) => {
81
+ let x = WasmI32.load(WasmI32.fromGrain(value), _FLOAT32_VALUE_OFFSET)
61
82
  let result = newInt32(x)
62
83
  WasmI32.toGrain(result): Int32
63
84
  }
package/int32.md CHANGED
@@ -33,7 +33,7 @@ No other changes yet.
33
33
  </details>
34
34
 
35
35
  ```grain
36
- fromNumber : (number: Number) => Int32
36
+ fromNumber: (number: Number) => Int32
37
37
  ```
38
38
 
39
39
  Converts a Number to an Int32.
@@ -58,7 +58,7 @@ No other changes yet.
58
58
  </details>
59
59
 
60
60
  ```grain
61
- toNumber : (value: Int32) => Number
61
+ toNumber: (value: Int32) => Number
62
62
  ```
63
63
 
64
64
  Converts an Int32 to a Number.
@@ -83,7 +83,7 @@ No other changes yet.
83
83
  </details>
84
84
 
85
85
  ```grain
86
- fromUint32 : (number: Uint32) => Int32
86
+ fromUint32: (number: Uint32) => Int32
87
87
  ```
88
88
 
89
89
  Converts a Uint32 to an Int32.
@@ -106,6 +106,41 @@ Examples:
106
106
  Int32.fromUint32(1ul) == 1l
107
107
  ```
108
108
 
109
+ ### Int32.**reinterpretFloat32**
110
+
111
+ <details disabled>
112
+ <summary tabindex="-1">Added in <code>0.7.0</code></summary>
113
+ No other changes yet.
114
+ </details>
115
+
116
+ ```grain
117
+ reinterpretFloat32: (value: Float32) => Int32
118
+ ```
119
+
120
+ Interprets a Float32 as an Int32.
121
+
122
+ Parameters:
123
+
124
+ |param|type|description|
125
+ |-----|----|-----------|
126
+ |`value`|`Float32`|The value to convert|
127
+
128
+ Returns:
129
+
130
+ |type|description|
131
+ |----|-----------|
132
+ |`Int32`|The Float32 interpreted as an Int32|
133
+
134
+ Examples:
135
+
136
+ ```grain
137
+ Int32.reinterpretFloat32(1.0f) == 1065353216l
138
+ ```
139
+
140
+ ```grain
141
+ Int32.reinterpretFloat32(-1.0f) == -1065353216l
142
+ ```
143
+
109
144
  ### Int32.**incr**
110
145
 
111
146
  <details disabled>
@@ -114,7 +149,7 @@ No other changes yet.
114
149
  </details>
115
150
 
116
151
  ```grain
117
- incr : (value: Int32) => Int32
152
+ incr: (value: Int32) => Int32
118
153
  ```
119
154
 
120
155
  Increments the value by one.
@@ -149,7 +184,7 @@ No other changes yet.
149
184
  </details>
150
185
 
151
186
  ```grain
152
- decr : (value: Int32) => Int32
187
+ decr: (value: Int32) => Int32
153
188
  ```
154
189
 
155
190
  Decrements the value by one.
@@ -191,7 +226,7 @@ Int32.decr(0l) == -1l
191
226
  </details>
192
227
 
193
228
  ```grain
194
- (+) : (x: Int32, y: Int32) => Int32
229
+ (+): (x: Int32, y: Int32) => Int32
195
230
  ```
196
231
 
197
232
  Computes the sum of its operands.
@@ -231,7 +266,7 @@ assert 1l + 1l == 2l
231
266
  </details>
232
267
 
233
268
  ```grain
234
- (-) : (x: Int32, y: Int32) => Int32
269
+ (-): (x: Int32, y: Int32) => Int32
235
270
  ```
236
271
 
237
272
  Computes the difference of its operands.
@@ -271,7 +306,7 @@ assert 2l - 1l == 1l
271
306
  </details>
272
307
 
273
308
  ```grain
274
- (*) : (x: Int32, y: Int32) => Int32
309
+ (*): (x: Int32, y: Int32) => Int32
275
310
  ```
276
311
 
277
312
  Computes the product of its operands.
@@ -311,7 +346,7 @@ assert 2l * 2l == 4l
311
346
  </details>
312
347
 
313
348
  ```grain
314
- (/) : (x: Int32, y: Int32) => Int32
349
+ (/): (x: Int32, y: Int32) => Int32
315
350
  ```
316
351
 
317
352
  Computes the quotient of its operands using signed division.
@@ -344,7 +379,7 @@ No other changes yet.
344
379
  </details>
345
380
 
346
381
  ```grain
347
- rem : (x: Int32, y: Int32) => Int32
382
+ rem: (x: Int32, y: Int32) => Int32
348
383
  ```
349
384
 
350
385
  Computes the remainder of the division of its operands using signed division.
@@ -383,7 +418,7 @@ Int32.rem(8l, 3l) == 2l
383
418
  </details>
384
419
 
385
420
  ```grain
386
- (%) : (x: Int32, y: Int32) => Int32
421
+ (%): (x: Int32, y: Int32) => Int32
387
422
  ```
388
423
 
389
424
  Computes the remainder of the division of the first operand by the second.
@@ -423,7 +458,7 @@ No other changes yet.
423
458
  </details>
424
459
 
425
460
  ```grain
426
- rotl : (value: Int32, amount: Int32) => Int32
461
+ rotl: (value: Int32, amount: Int32) => Int32
427
462
  ```
428
463
 
429
464
  Rotates the bits of the value left by the given number of bits.
@@ -459,7 +494,7 @@ No other changes yet.
459
494
  </details>
460
495
 
461
496
  ```grain
462
- rotr : (value: Int32, amount: Int32) => Int32
497
+ rotr: (value: Int32, amount: Int32) => Int32
463
498
  ```
464
499
 
465
500
  Rotates the bits of the value right by the given number of bits.
@@ -502,7 +537,7 @@ Int32.rotr(4l, 2l) == 1l
502
537
  </details>
503
538
 
504
539
  ```grain
505
- (<<) : (value: Int32, amount: Int32) => Int32
540
+ (<<): (value: Int32, amount: Int32) => Int32
506
541
  ```
507
542
 
508
543
  Shifts the bits of the value left by the given number of bits.
@@ -542,7 +577,7 @@ assert (5l << 1l) == 10l
542
577
  </details>
543
578
 
544
579
  ```grain
545
- (>>) : (value: Int32, amount: Int32) => Int32
580
+ (>>): (value: Int32, amount: Int32) => Int32
546
581
  ```
547
582
 
548
583
  Shifts the bits of the value right by the given number of bits, preserving the sign bit.
@@ -582,7 +617,7 @@ assert (5l >> 1l) == 2l
582
617
  </details>
583
618
 
584
619
  ```grain
585
- (==) : (x: Int32, y: Int32) => Bool
620
+ (==): (x: Int32, y: Int32) => Bool
586
621
  ```
587
622
 
588
623
  Checks if the first value is equal to the second value.
@@ -622,7 +657,7 @@ assert 1l == 1l
622
657
  </details>
623
658
 
624
659
  ```grain
625
- (!=) : (x: Int32, y: Int32) => Bool
660
+ (!=): (x: Int32, y: Int32) => Bool
626
661
  ```
627
662
 
628
663
  Checks if the first value is not equal to the second value.
@@ -655,7 +690,7 @@ No other changes yet.
655
690
  </details>
656
691
 
657
692
  ```grain
658
- eqz : (value: Int32) => Bool
693
+ eqz: (value: Int32) => Bool
659
694
  ```
660
695
 
661
696
  Checks if the given value is equal to zero.
@@ -697,7 +732,7 @@ Int32.eqz(1l) == false
697
732
  </details>
698
733
 
699
734
  ```grain
700
- (<) : (x: Int32, y: Int32) => Bool
735
+ (<): (x: Int32, y: Int32) => Bool
701
736
  ```
702
737
 
703
738
  Checks if the first value is less than the second value.
@@ -737,7 +772,7 @@ assert 1l < 2l
737
772
  </details>
738
773
 
739
774
  ```grain
740
- (>) : (x: Int32, y: Int32) => Bool
775
+ (>): (x: Int32, y: Int32) => Bool
741
776
  ```
742
777
 
743
778
  Checks if the first value is greater than the second value.
@@ -777,7 +812,7 @@ assert 2l > 1l
777
812
  </details>
778
813
 
779
814
  ```grain
780
- (<=) : (x: Int32, y: Int32) => Bool
815
+ (<=): (x: Int32, y: Int32) => Bool
781
816
  ```
782
817
 
783
818
  Checks if the first value is less than or equal to the second value.
@@ -822,7 +857,7 @@ assert 1l <= 1l
822
857
  </details>
823
858
 
824
859
  ```grain
825
- (>=) : (x: Int32, y: Int32) => Bool
860
+ (>=): (x: Int32, y: Int32) => Bool
826
861
  ```
827
862
 
828
863
  Checks if the first value is greater than or equal to the second value.
@@ -860,7 +895,7 @@ No other changes yet.
860
895
  </details>
861
896
 
862
897
  ```grain
863
- lnot : (value: Int32) => Int32
898
+ lnot: (value: Int32) => Int32
864
899
  ```
865
900
 
866
901
  Computes the bitwise NOT of the given value.
@@ -898,7 +933,7 @@ Int32.lnot(-5l) == 4l
898
933
  </details>
899
934
 
900
935
  ```grain
901
- (&) : (x: Int32, y: Int32) => Int32
936
+ (&): (x: Int32, y: Int32) => Int32
902
937
  ```
903
938
 
904
939
  Computes the bitwise AND (`&`) on the given operands.
@@ -938,7 +973,7 @@ assert (3l & 4l) == 0l
938
973
  </details>
939
974
 
940
975
  ```grain
941
- (|) : (x: Int32, y: Int32) => Int32
976
+ (|): (x: Int32, y: Int32) => Int32
942
977
  ```
943
978
 
944
979
  Computes the bitwise OR (`|`) on the given operands.
@@ -978,7 +1013,7 @@ assert (3l | 4l) == 7l
978
1013
  </details>
979
1014
 
980
1015
  ```grain
981
- (^) : (x: Int32, y: Int32) => Int32
1016
+ (^): (x: Int32, y: Int32) => Int32
982
1017
  ```
983
1018
 
984
1019
  Computes the bitwise XOR (`^`) on the given operands.
@@ -1011,7 +1046,7 @@ No other changes yet.
1011
1046
  </details>
1012
1047
 
1013
1048
  ```grain
1014
- clz : (value: Int32) => Int32
1049
+ clz: (value: Int32) => Int32
1015
1050
  ```
1016
1051
 
1017
1052
  Counts the number of leading zero bits in the value.
@@ -1046,7 +1081,7 @@ No other changes yet.
1046
1081
  </details>
1047
1082
 
1048
1083
  ```grain
1049
- ctz : (value: Int32) => Int32
1084
+ ctz: (value: Int32) => Int32
1050
1085
  ```
1051
1086
 
1052
1087
  Counts the number of trailing zero bits in the value.
@@ -1081,7 +1116,7 @@ No other changes yet.
1081
1116
  </details>
1082
1117
 
1083
1118
  ```grain
1084
- popcnt : (value: Int32) => Int32
1119
+ popcnt: (value: Int32) => Int32
1085
1120
  ```
1086
1121
 
1087
1122
  Counts the number of bits set to `1` in the value, also known as a population count.
@@ -1116,7 +1151,7 @@ No other changes yet.
1116
1151
  </details>
1117
1152
 
1118
1153
  ```grain
1119
- (**) : (base: Int32, power: Int32) => Int32
1154
+ (**): (base: Int32, power: Int32) => Int32
1120
1155
  ```
1121
1156
 
1122
1157
  Computes the exponentiation of the given base and power.
package/int64.gr CHANGED
@@ -10,6 +10,13 @@
10
10
  */
11
11
  module Int64
12
12
 
13
+ from "runtime/unsafe/offsets" include Offsets
14
+ // TODO(#703): Use `_VALUE_OFFSET` throughout this module
15
+ use Offsets.{
16
+ _INT64_VALUE_OFFSET as _VALUE_OFFSET,
17
+ _UINT64_VALUE_OFFSET,
18
+ _FLOAT64_VALUE_OFFSET,
19
+ }
13
20
  from "runtime/unsafe/wasmi32" include WasmI32
14
21
  from "runtime/unsafe/wasmi64" include WasmI64
15
22
  use WasmI64.{ (==), (!=), (&), (|), (^), (<<), (>>), (<), (<=), (>), (>=) }
@@ -38,7 +45,25 @@ provide { fromNumber, toNumber }
38
45
  */
39
46
  @unsafe
40
47
  provide let fromUint64 = (number: Uint64) => {
41
- let x = WasmI64.load(WasmI32.fromGrain(number), 8n)
48
+ let x = WasmI64.load(WasmI32.fromGrain(number), _UINT64_VALUE_OFFSET)
49
+ let result = newInt64(x)
50
+ WasmI32.toGrain(result): Int64
51
+ }
52
+
53
+ /**
54
+ * Interprets a Float64 as an Int64.
55
+ *
56
+ * @param value: The value to convert
57
+ * @returns The Float64 interpreted as an Int64
58
+ *
59
+ * @example assert Int64.reinterpretFloat64(1.0d) == 4607182418800017408L
60
+ * @example assert Int64.reinterpretFloat64(-1.0d) == -4616189618054758400L
61
+ *
62
+ * @since v0.7.0
63
+ */
64
+ @unsafe
65
+ provide let reinterpretFloat64 = (value: Float64) => {
66
+ let x = WasmI64.load(WasmI32.fromGrain(value), _FLOAT64_VALUE_OFFSET)
42
67
  let result = newInt64(x)
43
68
  WasmI32.toGrain(result): Int64
44
69
  }