@grain/stdlib 0.6.4 → 0.6.5

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/float64.md CHANGED
@@ -480,3 +480,167 @@ use Float64.{ (>=) }
480
480
  assert -1.0d >= -1.0d
481
481
  ```
482
482
 
483
+ ### Float64.**isNaN**
484
+
485
+ <details disabled>
486
+ <summary tabindex="-1">Added in <code>0.6.5</code></summary>
487
+ No other changes yet.
488
+ </details>
489
+
490
+ ```grain
491
+ isNaN : (x: Float64) => Bool
492
+ ```
493
+
494
+ Checks if the value is a float NaN value (Not A Number).
495
+
496
+ Parameters:
497
+
498
+ |param|type|description|
499
+ |-----|----|-----------|
500
+ |`x`|`Float64`|The value to check|
501
+
502
+ Returns:
503
+
504
+ |type|description|
505
+ |----|-----------|
506
+ |`Bool`|`true` if the value is NaN, otherwise `false`|
507
+
508
+ Examples:
509
+
510
+ ```grain
511
+ Float64.isNaN(NaNd)
512
+ ```
513
+
514
+ ```grain
515
+ Float64.isNaN(Infinityd) == false
516
+ ```
517
+
518
+ ```grain
519
+ Float64.isNaN(-Infinityd) == false
520
+ ```
521
+
522
+ ```grain
523
+ Float64.isNaN(0.5d) == false
524
+ ```
525
+
526
+ ```grain
527
+ Float64.isNaN(1.0d) == false
528
+ ```
529
+
530
+ ### Float64.**isInfinite**
531
+
532
+ <details disabled>
533
+ <summary tabindex="-1">Added in <code>0.6.5</code></summary>
534
+ No other changes yet.
535
+ </details>
536
+
537
+ ```grain
538
+ isInfinite : (x: Float64) => Bool
539
+ ```
540
+
541
+ Checks if a float is infinite, that is either of positive or negative infinity.
542
+
543
+ Parameters:
544
+
545
+ |param|type|description|
546
+ |-----|----|-----------|
547
+ |`x`|`Float64`|The value to check|
548
+
549
+ Returns:
550
+
551
+ |type|description|
552
+ |----|-----------|
553
+ |`Bool`|`true` if the value is infinite or `false` otherwise|
554
+
555
+ Examples:
556
+
557
+ ```grain
558
+ Float64.isInfinite(Infinityd)
559
+ ```
560
+
561
+ ```grain
562
+ Float64.isInfinite(-Infinityd)
563
+ ```
564
+
565
+ ```grain
566
+ Float64.isInfinite(NaNd) == false
567
+ ```
568
+
569
+ ```grain
570
+ Float64.isInfinite(0.5d) == false
571
+ ```
572
+
573
+ ```grain
574
+ Float64.isInfinite(1.0d) == false
575
+ ```
576
+
577
+ ### Float64.**abs**
578
+
579
+ <details disabled>
580
+ <summary tabindex="-1">Added in <code>0.6.5</code></summary>
581
+ No other changes yet.
582
+ </details>
583
+
584
+ ```grain
585
+ abs : (x: Float64) => Float64
586
+ ```
587
+
588
+ Returns the absolute value. That is, it returns `x` if `x` is positive or zero and the negation of `x` if `x` is negative.
589
+
590
+ Parameters:
591
+
592
+ |param|type|description|
593
+ |-----|----|-----------|
594
+ |`x`|`Float64`|The operand|
595
+
596
+ Returns:
597
+
598
+ |type|description|
599
+ |----|-----------|
600
+ |`Float64`|The absolute value of the operand|
601
+
602
+ Examples:
603
+
604
+ ```grain
605
+ Float64.abs(-1.0d) == 1.0d
606
+ ```
607
+
608
+ ```grain
609
+ Float64.abs(5.0d) == 5.0d
610
+ ```
611
+
612
+ ### Float64.**neg**
613
+
614
+ <details disabled>
615
+ <summary tabindex="-1">Added in <code>0.6.5</code></summary>
616
+ No other changes yet.
617
+ </details>
618
+
619
+ ```grain
620
+ neg : (x: Float64) => Float64
621
+ ```
622
+
623
+ Returns the negation of its operand.
624
+
625
+ Parameters:
626
+
627
+ |param|type|description|
628
+ |-----|----|-----------|
629
+ |`x`|`Float64`|The operand|
630
+
631
+ Returns:
632
+
633
+ |type|description|
634
+ |----|-----------|
635
+ |`Float64`|The negated operand|
636
+
637
+ Examples:
638
+
639
+ ```grain
640
+ Float64.neg(-1.0d) == 1.0d
641
+ ```
642
+
643
+ ```grain
644
+ Float64.neg(1.0d) == -1.0d
645
+ ```
646
+
package/hash.gr CHANGED
@@ -262,6 +262,8 @@ provide let hash = anything => {
262
262
  }
263
263
 
264
264
  hashOne(WasmI32.fromGrain(anything), 0n)
265
+ ignore(anything)
266
+
265
267
  finalize(0n)
266
268
 
267
269
  // Tag the number on the way out.
package/int32.gr CHANGED
@@ -3,6 +3,9 @@
3
3
  *
4
4
  * @example from "int32" include Int32
5
5
  *
6
+ * @example 1l
7
+ * @example -1l
8
+ *
6
9
  * @since v0.2.0
7
10
  */
8
11
  module Int32
@@ -48,6 +51,8 @@ provide { fromNumber, toNumber }
48
51
  * @param number: The value to convert
49
52
  * @returns The Uint32 represented as an Int32
50
53
  *
54
+ * @example Int32.fromUint32(1ul) == 1l
55
+ *
51
56
  * @since v0.6.0
52
57
  */
53
58
  @unsafe
@@ -63,6 +68,9 @@ provide let fromUint32 = (number: Uint32) => {
63
68
  * @param value: The value to increment
64
69
  * @returns The incremented value
65
70
  *
71
+ * @example Int32.incr(1l) == 2l
72
+ * @example Int32.incr(-2l) == -1l
73
+ *
66
74
  * @since v0.2.0
67
75
  */
68
76
  @unsafe
@@ -78,6 +86,9 @@ provide let incr = (value: Int32) => {
78
86
  * @param value: The value to decrement
79
87
  * @returns The decremented value
80
88
  *
89
+ * @example Int32.decr(2l) == 1l
90
+ * @example Int32.decr(0l) == -1l
91
+ *
81
92
  * @since v0.2.0
82
93
  */
83
94
  @unsafe
@@ -94,6 +105,10 @@ provide let decr = (value: Int32) => {
94
105
  * @param y: The second operand
95
106
  * @returns The sum of the two operands
96
107
  *
108
+ * @example
109
+ * use Int32.{ (+) }
110
+ * assert 1l + 1l == 2l
111
+ *
97
112
  * @since v0.6.0
98
113
  * @history v0.2.0: Originally named `add`
99
114
  */
@@ -112,6 +127,10 @@ provide let (+) = (x: Int32, y: Int32) => {
112
127
  * @param y: The second operand
113
128
  * @returns The difference of the two operands
114
129
  *
130
+ * @example
131
+ * use Int32.{ (-) }
132
+ * assert 2l - 1l == 1l
133
+ *
115
134
  * @since v0.6.0
116
135
  * @history v0.2.0: Originally named `sub`
117
136
  */
@@ -130,6 +149,10 @@ provide let (-) = (x: Int32, y: Int32) => {
130
149
  * @param y: The second operand
131
150
  * @returns The product of the two operands
132
151
  *
152
+ * @example
153
+ * use Int32.{ (*) }
154
+ * assert 2l * 2l == 4l
155
+ *
133
156
  * @since v0.6.0
134
157
  * @history v0.2.0: Originally named `mul`
135
158
  */
@@ -148,6 +171,10 @@ provide let (*) = (x: Int32, y: Int32) => {
148
171
  * @param y: The second operand
149
172
  * @returns The quotient of its operands
150
173
  *
174
+ * @example
175
+ * use Int32.{ (/) }
176
+ * assert 8l / 2l == 4l
177
+ *
151
178
  * @since v0.6.0
152
179
  * @history v0.2.0: Originally named `div`
153
180
  */
@@ -166,6 +193,8 @@ provide let (/) = (x: Int32, y: Int32) => {
166
193
  * @param y: The second operand
167
194
  * @returns The remainder of its operands
168
195
  *
196
+ * @example Int32.rem(8l, 3l) == 2l
197
+ *
169
198
  * @since v0.2.0
170
199
  */
171
200
  @unsafe
@@ -193,6 +222,10 @@ let abs = n => {
193
222
  *
194
223
  * @throws ModuloByZero: When `y` is zero
195
224
  *
225
+ * @example
226
+ * use Int32.{ (%) }
227
+ * assert -5l % 3l == 1l
228
+ *
196
229
  * @since v0.6.0
197
230
  * @history v0.2.0: Originally named `mod`
198
231
  */
@@ -225,6 +258,9 @@ provide let (%) = (x: Int32, y: Int32) => {
225
258
  * @param amount: The number of bits to rotate by
226
259
  * @returns The rotated value
227
260
  *
261
+ * @example Int32.rotl(1l, 1l) == 2l
262
+ * @example Int32.rotl(1l, 2l) == 4l
263
+ *
228
264
  * @since v0.4.0
229
265
  */
230
266
  @unsafe
@@ -242,6 +278,9 @@ provide let rotl = (value: Int32, amount: Int32) => {
242
278
  * @param amount: The number of bits to rotate by
243
279
  * @returns The rotated value
244
280
  *
281
+ * @example Int32.rotr(2l, 1l) == 1l
282
+ * @example Int32.rotr(4l, 2l) == 1l
283
+ *
245
284
  * @since v0.4.0
246
285
  */
247
286
  @unsafe
@@ -259,6 +298,10 @@ provide let rotr = (value: Int32, amount: Int32) => {
259
298
  * @param amount: The number of bits to shift by
260
299
  * @returns The shifted value
261
300
  *
301
+ * @example
302
+ * use Int32.{ (<<) }
303
+ * assert (5l << 1l) == 10l
304
+ *
262
305
  * @since v0.6.0
263
306
  * @history v0.2.0: Originally named `shl`
264
307
  */
@@ -277,6 +320,10 @@ provide let (<<) = (value: Int32, amount: Int32) => {
277
320
  * @param amount: The amount to shift by
278
321
  * @returns The shifted value
279
322
  *
323
+ * @example
324
+ * use Int32.{ (>>) }
325
+ * assert (5l >> 1l) == 2l
326
+ *
280
327
  * @since v0.6.0
281
328
  * @history v0.2.0: Originally named `shr`
282
329
  */
@@ -295,6 +342,10 @@ provide let (>>) = (value: Int32, amount: Int32) => {
295
342
  * @param y: The second value
296
343
  * @returns `true` if the first value is equal to the second value or `false` otherwise
297
344
  *
345
+ * @example
346
+ * use Int32.{ (==) }
347
+ * assert 1l == 1l
348
+ *
298
349
  * @since v0.6.0
299
350
  * @history v0.4.0: Originally named `eq`
300
351
  */
@@ -312,6 +363,10 @@ provide let (==) = (x: Int32, y: Int32) => {
312
363
  * @param y: The second value
313
364
  * @returns `true` if the first value is not equal to the second value or `false` otherwise
314
365
  *
366
+ * @example
367
+ * use Int32.{ (!=) }
368
+ * assert 1l != 2l
369
+ *
315
370
  * @since v0.6.0
316
371
  * @history v0.4.0: Originally named `ne`
317
372
  */
@@ -328,6 +383,9 @@ provide let (!=) = (x: Int32, y: Int32) => {
328
383
  * @param value: The value to inspect
329
384
  * @returns `true` if the first value is equal to zero or `false` otherwise
330
385
  *
386
+ * @example Int32.eqz(0l) == true
387
+ * @example Int32.eqz(1l) == false
388
+ *
331
389
  * @since v0.4.0
332
390
  */
333
391
  @unsafe
@@ -343,6 +401,10 @@ provide let eqz = (value: Int32) => {
343
401
  * @param y: The second value
344
402
  * @returns `true` if the first value is less than the second value or `false` otherwise
345
403
  *
404
+ * @example
405
+ * use Int32.{ (<) }
406
+ * assert 1l < 2l
407
+ *
346
408
  * @since v0.6.0
347
409
  * @history v0.2.0: Originally named `lt`
348
410
  */
@@ -360,6 +422,10 @@ provide let (<) = (x: Int32, y: Int32) => {
360
422
  * @param y: The second value
361
423
  * @returns `true` if the first value is greater than the second value or `false` otherwise
362
424
  *
425
+ * @example
426
+ * use Int32.{ (>) }
427
+ * assert 2l > 1l
428
+ *
363
429
  * @since v0.6.0
364
430
  * @history v0.2.0: Originally named `gt`
365
431
  */
@@ -377,6 +443,13 @@ provide let (>) = (x: Int32, y: Int32) => {
377
443
  * @param y: The second value
378
444
  * @returns `true` if the first value is less than or equal to the second value or `false` otherwise
379
445
  *
446
+ * @example
447
+ * use Int32.{ (<=) }
448
+ * assert 1l <= 2l
449
+ * @example
450
+ * use Int32.{ (<=) }
451
+ * assert 1l <= 1l
452
+ *
380
453
  * @since v0.6.0
381
454
  * @history v0.2.0: Originally named `lte`
382
455
  */
@@ -394,6 +467,13 @@ provide let (<=) = (x: Int32, y: Int32) => {
394
467
  * @param y: The second value
395
468
  * @returns `true` if the first value is greater than or equal to the second value or `false` otherwise
396
469
  *
470
+ * @example
471
+ * use Int32.{ (>=) }
472
+ * assert 2l >= 1l
473
+ * @example
474
+ * use Int32.{ (>=) }
475
+ * assert 1l >= 1l
476
+ *
397
477
  * @since v0.6.0
398
478
  * @history v0.2.0: Originally named `gte`
399
479
  */
@@ -410,6 +490,8 @@ provide let (>=) = (x: Int32, y: Int32) => {
410
490
  * @param value: The given value
411
491
  * @returns Containing the inverted bits of the given value
412
492
  *
493
+ * @example Int32.lnot(-5l) == 4l
494
+ *
413
495
  * @since v0.2.0
414
496
  */
415
497
  @unsafe
@@ -426,6 +508,10 @@ provide let lnot = (value: Int32) => {
426
508
  * @param y: The second operand
427
509
  * @returns Containing a `1` in each bit position for which the corresponding bits of both operands are `1`
428
510
  *
511
+ * @example
512
+ * use Int32.{ (&) }
513
+ * assert (3l & 4l) == 0l
514
+ *
429
515
  * @since v0.6.0
430
516
  * @history v0.2.0: Originally named `land`
431
517
  */
@@ -444,6 +530,10 @@ provide let (&) = (x: Int32, y: Int32) => {
444
530
  * @param y: The second operand
445
531
  * @returns Containing a `1` in each bit position for which the corresponding bits of either or both operands are `1`
446
532
  *
533
+ * @example
534
+ * use Int32.{ (|) }
535
+ * assert (3l | 4l) == 7l
536
+ *
447
537
  * @since v0.6.0
448
538
  * @history v0.2.0: Originally named `lor`
449
539
  */
@@ -462,6 +552,10 @@ provide let (|) = (x: Int32, y: Int32) => {
462
552
  * @param y: The second operand
463
553
  * @returns Containing a `1` in each bit position for which the corresponding bits of either but not both operands are `1`
464
554
  *
555
+ * @example
556
+ * use Int32.{ (^) }
557
+ * assert (3l ^ 5l) == 6l
558
+ *
465
559
  * @since v0.6.0
466
560
  * @history v0.2.0: Originally named `lxor`
467
561
  */
@@ -479,6 +573,9 @@ provide let (^) = (x: Int32, y: Int32) => {
479
573
  * @param value: The value to inspect
480
574
  * @returns The amount of leading zeros
481
575
  *
576
+ * @example Int32.clz(1l) == 31l
577
+ * @example Int32.clz(4l) == 29l
578
+ *
482
579
  * @since v0.4.0
483
580
  */
484
581
  @unsafe
@@ -494,6 +591,9 @@ provide let clz = (value: Int32) => {
494
591
  * @param value: The value to inspect
495
592
  * @returns The amount of trailing zeros
496
593
  *
594
+ * @example Int32.ctz(1l) == 0l
595
+ * @example Int32.ctz(4l) == 2l
596
+ *
497
597
  * @since v0.4.0
498
598
  */
499
599
  @unsafe
@@ -509,6 +609,9 @@ provide let ctz = (value: Int32) => {
509
609
  * @param value: The value to inspect
510
610
  * @returns The amount of 1-bits in its operand
511
611
  *
612
+ * @example Int32.popcnt(1l) == 1l
613
+ * @example Int32.popcnt(3l) == 2l
614
+ *
512
615
  * @since v0.4.0
513
616
  */
514
617
  @unsafe
@@ -538,6 +641,10 @@ let rec expBySquaring = (y, x, n) => {
538
641
  * @param power: The exponent number
539
642
  * @returns The base raised to the given power
540
643
  *
644
+ * @example
645
+ * from Int32 use { (**) }
646
+ * assert 2l ** 3l == 8l
647
+ *
541
648
  * @since v0.6.0
542
649
  */
543
650
  provide let (**) = (base, power) => {