@grain/stdlib 0.6.4 → 0.6.6
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 +21 -0
- package/array.gr +2 -0
- package/bytes.gr +38 -7
- package/float32.gr +68 -0
- package/float32.md +164 -0
- package/float64.gr +87 -16
- package/float64.md +164 -0
- package/hash.gr +2 -0
- package/int32.gr +107 -0
- package/int32.md +235 -0
- package/int64.gr +107 -0
- package/int64.md +235 -0
- package/list.gr +59 -18
- package/map.gr +3 -2
- package/package.json +1 -1
- package/pervasives.md +10 -3
- package/runtime/numbers.gr +181 -100
- package/runtime/string.gr +1 -0
- package/runtime/string.md +10 -3
- package/string.gr +291 -72
- package/string.md +108 -0
- package/uint16.gr +81 -0
- package/uint16.md +161 -0
- package/uint8.gr +81 -0
- package/uint8.md +161 -0
- package/wasi/file.gr +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.6](https://github.com/grain-lang/grain/compare/stdlib-v0.6.5...stdlib-v0.6.6) (2024-08-12)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **stdlib:** Synchronize Grain versions
|
|
9
|
+
|
|
10
|
+
## [0.6.5](https://github.com/grain-lang/grain/compare/stdlib-v0.6.4...stdlib-v0.6.5) (2024-07-31)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* **stdlib:** Add `abs`, `neg`, `isNaN`, `isInfinite` to `Float32` ([#2116](https://github.com/grain-lang/grain/issues/2116)) ([fb1d481](https://github.com/grain-lang/grain/commit/fb1d481715974c6639588a9a72d4739516319e40))
|
|
16
|
+
* **stdlib:** Add `abs`, `neg`, `isNaN`, `isInfinite` to `Float64` ([#2117](https://github.com/grain-lang/grain/issues/2117)) ([9469346](https://github.com/grain-lang/grain/commit/9469346fa26a4df4188e53f8994d5692286d2e9f))
|
|
17
|
+
* **stdlib:** Add `forEachChar`, `forEachCharI`, `map` and `mapi` to String module ([#1864](https://github.com/grain-lang/grain/issues/1864)) ([4305e82](https://github.com/grain-lang/grain/commit/4305e829e160c6d2e49a249e3ec19baaa3c33744))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* **stdlib:** Ensure references are retained in unsafe stdlib functions ([#2118](https://github.com/grain-lang/grain/issues/2118)) ([639856f](https://github.com/grain-lang/grain/commit/639856f9f99edb00bfb19a0ec6f298d48972d3e4))
|
|
23
|
+
|
|
3
24
|
## [0.6.4](https://github.com/grain-lang/grain/compare/stdlib-v0.6.3...stdlib-v0.6.4) (2024-06-27)
|
|
4
25
|
|
|
5
26
|
|
package/array.gr
CHANGED
|
@@ -91,6 +91,7 @@ provide let make = (length: Number, item: a) => {
|
|
|
91
91
|
_ARRAY_START_OFFSET
|
|
92
92
|
)
|
|
93
93
|
}
|
|
94
|
+
ignore(item)
|
|
94
95
|
WasmI32.toGrain(array): Array<a>
|
|
95
96
|
}
|
|
96
97
|
|
|
@@ -988,6 +989,7 @@ provide let join = (separator: String, items: Array<String>) => {
|
|
|
988
989
|
if (i != arrLen) Memory.copy(offset, sepPtr, sepSize)
|
|
989
990
|
offset += sepSize
|
|
990
991
|
}
|
|
992
|
+
ignore(separator)
|
|
991
993
|
WasmI32.toGrain(newString): String
|
|
992
994
|
}
|
|
993
995
|
|
package/bytes.gr
CHANGED
|
@@ -113,6 +113,7 @@ provide let fromString = (string: String) => {
|
|
|
113
113
|
let size = getSize(src)
|
|
114
114
|
let dst = allocateBytes(size)
|
|
115
115
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET, size)
|
|
116
|
+
ignore(string)
|
|
116
117
|
WasmI32.toGrain(dst): Bytes
|
|
117
118
|
}
|
|
118
119
|
|
|
@@ -134,6 +135,7 @@ provide let toString = (bytes: Bytes) => {
|
|
|
134
135
|
let size = getSize(src)
|
|
135
136
|
let dst = allocateString(size)
|
|
136
137
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET, size)
|
|
138
|
+
ignore(bytes)
|
|
137
139
|
WasmI32.toGrain(dst): String
|
|
138
140
|
}
|
|
139
141
|
|
|
@@ -151,7 +153,9 @@ provide let toString = (bytes: Bytes) => {
|
|
|
151
153
|
@unsafe
|
|
152
154
|
provide let length = (bytes: Bytes) => {
|
|
153
155
|
let b = WasmI32.fromGrain(bytes)
|
|
154
|
-
Conv.wasmI32ToNumber(getSize(b))
|
|
156
|
+
let result = Conv.wasmI32ToNumber(getSize(b))
|
|
157
|
+
ignore(bytes)
|
|
158
|
+
result
|
|
155
159
|
}
|
|
156
160
|
|
|
157
161
|
/**
|
|
@@ -171,6 +175,7 @@ provide let copy = (bytes: Bytes) => {
|
|
|
171
175
|
let size = getSize(src)
|
|
172
176
|
let dst = allocateBytes(size)
|
|
173
177
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET, size)
|
|
178
|
+
ignore(bytes)
|
|
174
179
|
WasmI32.toGrain(dst): Bytes
|
|
175
180
|
}
|
|
176
181
|
|
|
@@ -208,6 +213,7 @@ provide let slice = (start: Number, length: Number, bytes: Bytes) => {
|
|
|
208
213
|
let dst = allocateBytes(length)
|
|
209
214
|
let offset = start
|
|
210
215
|
Memory.copy(dst + _VALUE_OFFSET, src + _VALUE_OFFSET + start, length)
|
|
216
|
+
ignore(bytes)
|
|
211
217
|
WasmI32.toGrain(dst): Bytes
|
|
212
218
|
}
|
|
213
219
|
|
|
@@ -263,6 +269,7 @@ provide let resize = (left: Number, right: Number, bytes: Bytes) => {
|
|
|
263
269
|
len
|
|
264
270
|
)
|
|
265
271
|
}
|
|
272
|
+
ignore(bytes)
|
|
266
273
|
WasmI32.toGrain(dst): Bytes
|
|
267
274
|
}
|
|
268
275
|
|
|
@@ -298,11 +305,11 @@ provide let move = (
|
|
|
298
305
|
let srcIndexOrig = srcIndex
|
|
299
306
|
let dstIndexOrig = dstIndex
|
|
300
307
|
let lenthOrig = length
|
|
301
|
-
let
|
|
302
|
-
let srcSize = getSize(
|
|
308
|
+
let srcPtr = WasmI32.fromGrain(src)
|
|
309
|
+
let srcSize = getSize(srcPtr)
|
|
303
310
|
let srcIndex = coerceNumberToWasmI32(srcIndex)
|
|
304
|
-
let
|
|
305
|
-
let dstSize = getSize(
|
|
311
|
+
let dstPtr = WasmI32.fromGrain(dst)
|
|
312
|
+
let dstSize = getSize(dstPtr)
|
|
306
313
|
let dstIndex = coerceNumberToWasmI32(dstIndex)
|
|
307
314
|
let length = coerceNumberToWasmI32(length)
|
|
308
315
|
if (srcIndex + length > srcSize) {
|
|
@@ -313,10 +320,12 @@ provide let move = (
|
|
|
313
320
|
}
|
|
314
321
|
let end = srcIndex + length
|
|
315
322
|
Memory.copy(
|
|
316
|
-
|
|
317
|
-
|
|
323
|
+
dstPtr + _VALUE_OFFSET + dstIndex,
|
|
324
|
+
srcPtr + _VALUE_OFFSET + srcIndex,
|
|
318
325
|
length
|
|
319
326
|
)
|
|
327
|
+
ignore(src)
|
|
328
|
+
ignore(dst)
|
|
320
329
|
}
|
|
321
330
|
|
|
322
331
|
/**
|
|
@@ -362,6 +371,7 @@ provide let fill = (value: Uint8, bytes: Bytes) => {
|
|
|
362
371
|
let size = getSize(src)
|
|
363
372
|
let v = untagUint8(value)
|
|
364
373
|
Memory.fill(src + _VALUE_OFFSET, v, size)
|
|
374
|
+
ignore(bytes)
|
|
365
375
|
}
|
|
366
376
|
|
|
367
377
|
/**
|
|
@@ -383,6 +393,7 @@ provide let clear = (bytes: Bytes) => {
|
|
|
383
393
|
let src = WasmI32.fromGrain(bytes)
|
|
384
394
|
let size = getSize(src)
|
|
385
395
|
Memory.fill(src + _VALUE_OFFSET, 0n, size)
|
|
396
|
+
ignore(bytes)
|
|
386
397
|
}
|
|
387
398
|
|
|
388
399
|
/**
|
|
@@ -411,6 +422,7 @@ provide let getInt8 = (index: Number, bytes: Bytes) => {
|
|
|
411
422
|
let offset = coerceNumberToWasmI32(index)
|
|
412
423
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
413
424
|
let n = WasmI32.load8S(ptr + offset, _VALUE_OFFSET)
|
|
425
|
+
ignore(bytes)
|
|
414
426
|
tagInt8(n)
|
|
415
427
|
}
|
|
416
428
|
|
|
@@ -440,6 +452,7 @@ provide let setInt8 = (index: Number, value: Int8, bytes: Bytes) => {
|
|
|
440
452
|
let offset = coerceNumberToWasmI32(index)
|
|
441
453
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
442
454
|
let v = untagInt8(value)
|
|
455
|
+
ignore(bytes)
|
|
443
456
|
WasmI32.store8(ptr + offset, v, _VALUE_OFFSET)
|
|
444
457
|
}
|
|
445
458
|
|
|
@@ -469,6 +482,7 @@ provide let getUint8 = (index: Number, bytes: Bytes) => {
|
|
|
469
482
|
let offset = coerceNumberToWasmI32(index)
|
|
470
483
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
471
484
|
let n = WasmI32.load8U(ptr + offset, _VALUE_OFFSET)
|
|
485
|
+
ignore(bytes)
|
|
472
486
|
tagUint8(n)
|
|
473
487
|
}
|
|
474
488
|
|
|
@@ -498,6 +512,7 @@ provide let setUint8 = (index: Number, value: Uint8, bytes: Bytes) => {
|
|
|
498
512
|
checkIndexIsInBounds(offset, _INT8_BYTE_SIZE, size)
|
|
499
513
|
let v = untagUint8(value)
|
|
500
514
|
WasmI32.store8(ptr + offset, v, _VALUE_OFFSET)
|
|
515
|
+
ignore(bytes)
|
|
501
516
|
}
|
|
502
517
|
|
|
503
518
|
/**
|
|
@@ -526,6 +541,7 @@ provide let getInt16 = (index: Number, bytes: Bytes) => {
|
|
|
526
541
|
let offset = coerceNumberToWasmI32(index)
|
|
527
542
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
528
543
|
let n = WasmI32.load16S(ptr + offset, _VALUE_OFFSET)
|
|
544
|
+
ignore(bytes)
|
|
529
545
|
tagInt16(n)
|
|
530
546
|
}
|
|
531
547
|
|
|
@@ -556,6 +572,7 @@ provide let setInt16 = (index: Number, value: Int16, bytes: Bytes) => {
|
|
|
556
572
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
557
573
|
let v = untagInt16(value)
|
|
558
574
|
WasmI32.store16(ptr + offset, v, _VALUE_OFFSET)
|
|
575
|
+
ignore(bytes)
|
|
559
576
|
}
|
|
560
577
|
|
|
561
578
|
/**
|
|
@@ -584,6 +601,7 @@ provide let getUint16 = (index: Number, bytes: Bytes) => {
|
|
|
584
601
|
let offset = coerceNumberToWasmI32(index)
|
|
585
602
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
586
603
|
let n = WasmI32.load16U(ptr + offset, _VALUE_OFFSET)
|
|
604
|
+
ignore(bytes)
|
|
587
605
|
tagUint16(n)
|
|
588
606
|
}
|
|
589
607
|
|
|
@@ -613,6 +631,7 @@ provide let setUint16 = (index: Number, value: Uint16, bytes: Bytes) => {
|
|
|
613
631
|
checkIndexIsInBounds(offset, _INT16_BYTE_SIZE, size)
|
|
614
632
|
let v = untagUint16(value)
|
|
615
633
|
WasmI32.store16(ptr + offset, v, _VALUE_OFFSET)
|
|
634
|
+
ignore(bytes)
|
|
616
635
|
}
|
|
617
636
|
|
|
618
637
|
/**
|
|
@@ -640,6 +659,7 @@ provide let getInt32 = (index: Number, bytes: Bytes) => {
|
|
|
640
659
|
let offset = coerceNumberToWasmI32(index)
|
|
641
660
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
642
661
|
let n = WasmI32.load(ptr + offset, _VALUE_OFFSET)
|
|
662
|
+
ignore(bytes)
|
|
643
663
|
Conv.toInt32(n)
|
|
644
664
|
}
|
|
645
665
|
|
|
@@ -669,6 +689,7 @@ provide let setInt32 = (index: Number, value: Int32, bytes: Bytes) => {
|
|
|
669
689
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
670
690
|
let v = Conv.fromInt32(value)
|
|
671
691
|
WasmI32.store(ptr + offset, v, _VALUE_OFFSET)
|
|
692
|
+
ignore(bytes)
|
|
672
693
|
}
|
|
673
694
|
|
|
674
695
|
/**
|
|
@@ -696,6 +717,7 @@ provide let getUint32 = (index: Number, bytes: Bytes) => {
|
|
|
696
717
|
let offset = coerceNumberToWasmI32(index)
|
|
697
718
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
698
719
|
let n = WasmI32.load(ptr + offset, _VALUE_OFFSET)
|
|
720
|
+
ignore(bytes)
|
|
699
721
|
Conv.toUint32(n)
|
|
700
722
|
}
|
|
701
723
|
|
|
@@ -725,6 +747,7 @@ provide let setUint32 = (index: Number, value: Uint32, bytes: Bytes) => {
|
|
|
725
747
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
726
748
|
let v = Conv.fromUint32(value)
|
|
727
749
|
WasmI32.store(ptr + offset, v, _VALUE_OFFSET)
|
|
750
|
+
ignore(bytes)
|
|
728
751
|
}
|
|
729
752
|
|
|
730
753
|
/**
|
|
@@ -752,6 +775,7 @@ provide let getFloat32 = (index: Number, bytes: Bytes) => {
|
|
|
752
775
|
let offset = coerceNumberToWasmI32(index)
|
|
753
776
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
754
777
|
let n = WasmF32.load(ptr + offset, _VALUE_OFFSET)
|
|
778
|
+
ignore(bytes)
|
|
755
779
|
Conv.toFloat32(n)
|
|
756
780
|
}
|
|
757
781
|
|
|
@@ -781,6 +805,7 @@ provide let setFloat32 = (index: Number, value: Float32, bytes: Bytes) => {
|
|
|
781
805
|
checkIndexIsInBounds(offset, _INT32_BYTE_SIZE, size)
|
|
782
806
|
let v = Conv.fromFloat32(value)
|
|
783
807
|
WasmF32.store(ptr + offset, v, _VALUE_OFFSET)
|
|
808
|
+
ignore(bytes)
|
|
784
809
|
}
|
|
785
810
|
|
|
786
811
|
/**
|
|
@@ -808,6 +833,7 @@ provide let getInt64 = (index: Number, bytes: Bytes) => {
|
|
|
808
833
|
let offset = coerceNumberToWasmI32(index)
|
|
809
834
|
checkIndexIsInBounds(offset, _INT64_BYTE_SIZE, size)
|
|
810
835
|
let n = WasmI64.load(ptr + offset, _VALUE_OFFSET)
|
|
836
|
+
ignore(bytes)
|
|
811
837
|
Conv.toInt64(n)
|
|
812
838
|
}
|
|
813
839
|
|
|
@@ -837,6 +863,7 @@ provide let setInt64 = (index: Number, value: Int64, bytes: Bytes) => {
|
|
|
837
863
|
checkIndexIsInBounds(offset, _INT64_BYTE_SIZE, size)
|
|
838
864
|
let v = Conv.fromInt64(value)
|
|
839
865
|
WasmI64.store(ptr + offset, v, _VALUE_OFFSET)
|
|
866
|
+
ignore(bytes)
|
|
840
867
|
}
|
|
841
868
|
|
|
842
869
|
/**
|
|
@@ -864,6 +891,7 @@ provide let getUint64 = (index: Number, bytes: Bytes) => {
|
|
|
864
891
|
let offset = coerceNumberToWasmI32(index)
|
|
865
892
|
checkIndexIsInBounds(offset, _INT64_BYTE_SIZE, size)
|
|
866
893
|
let n = WasmI64.load(ptr + offset, _VALUE_OFFSET)
|
|
894
|
+
ignore(bytes)
|
|
867
895
|
Conv.toUint64(n)
|
|
868
896
|
}
|
|
869
897
|
|
|
@@ -893,6 +921,7 @@ provide let setUint64 = (index: Number, value: Uint64, bytes: Bytes) => {
|
|
|
893
921
|
checkIndexIsInBounds(offset, _INT64_BYTE_SIZE, size)
|
|
894
922
|
let v = Conv.fromUint64(value)
|
|
895
923
|
WasmI64.store(ptr + offset, v, _VALUE_OFFSET)
|
|
924
|
+
ignore(bytes)
|
|
896
925
|
}
|
|
897
926
|
|
|
898
927
|
/**
|
|
@@ -920,6 +949,7 @@ provide let getFloat64 = (index: Number, bytes: Bytes) => {
|
|
|
920
949
|
let offset = coerceNumberToWasmI32(index)
|
|
921
950
|
checkIndexIsInBounds(offset, _FLOAT64_BYTE_SIZE, size)
|
|
922
951
|
let n = WasmF64.load(ptr + offset, _VALUE_OFFSET)
|
|
952
|
+
ignore(bytes)
|
|
923
953
|
Conv.toFloat64(n)
|
|
924
954
|
}
|
|
925
955
|
|
|
@@ -949,4 +979,5 @@ provide let setFloat64 = (index: Number, value: Float64, bytes: Bytes) => {
|
|
|
949
979
|
checkIndexIsInBounds(offset, _FLOAT64_BYTE_SIZE, size)
|
|
950
980
|
let v = Conv.fromFloat64(value)
|
|
951
981
|
WasmF64.store(ptr + offset, v, _VALUE_OFFSET)
|
|
982
|
+
ignore(bytes)
|
|
952
983
|
}
|
package/float32.gr
CHANGED
|
@@ -247,3 +247,71 @@ provide let (>=) = (x: Float32, y: Float32) => {
|
|
|
247
247
|
let yv = WasmF32.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
248
248
|
xv >= yv
|
|
249
249
|
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Checks if the value is a float NaN value (Not A Number).
|
|
253
|
+
*
|
|
254
|
+
* @param x: The value to check
|
|
255
|
+
* @returns `true` if the value is NaN, otherwise `false`
|
|
256
|
+
*
|
|
257
|
+
* @example Float32.isNaN(NaNf)
|
|
258
|
+
* @example Float32.isNaN(Infinityf) == false
|
|
259
|
+
* @example Float32.isNaN(-Infinityf) == false
|
|
260
|
+
* @example Float32.isNaN(0.5f) == false
|
|
261
|
+
* @example Float32.isNaN(1.0f) == false
|
|
262
|
+
*
|
|
263
|
+
* @since v0.6.5
|
|
264
|
+
*/
|
|
265
|
+
provide let isNaN = (x: Float32) => x != x
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Checks if a float is infinite, that is either of positive or negative infinity.
|
|
269
|
+
*
|
|
270
|
+
* @param x: The value to check
|
|
271
|
+
* @returns `true` if the value is infinite or `false` otherwise
|
|
272
|
+
*
|
|
273
|
+
* @example Float32.isInfinite(Infinityf)
|
|
274
|
+
* @example Float32.isInfinite(-Infinityf)
|
|
275
|
+
* @example Float32.isInfinite(NaNf) == false
|
|
276
|
+
* @example Float32.isInfinite(0.5f) == false
|
|
277
|
+
* @example Float32.isInfinite(1.0f) == false
|
|
278
|
+
*
|
|
279
|
+
* @since v0.6.5
|
|
280
|
+
*/
|
|
281
|
+
provide let isInfinite = (x: Float32) => x == Infinityf || x == -Infinityf
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Returns the absolute value. That is, it returns `x` if `x` is positive or zero and the negation of `x` if `x` is negative.
|
|
285
|
+
*
|
|
286
|
+
* @param x: The operand
|
|
287
|
+
* @returns The absolute value of the operand
|
|
288
|
+
*
|
|
289
|
+
* @example Float32.abs(-1.0f) == 1.0f
|
|
290
|
+
* @example Float32.abs(5.0f) == 5.0f
|
|
291
|
+
*
|
|
292
|
+
* @since v0.6.5
|
|
293
|
+
*/
|
|
294
|
+
@unsafe
|
|
295
|
+
provide let abs = (x: Float32) => {
|
|
296
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
297
|
+
let ptr = newFloat32(WasmF32.abs(xv))
|
|
298
|
+
WasmI32.toGrain(ptr): Float32
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Returns the negation of its operand.
|
|
303
|
+
*
|
|
304
|
+
* @param x: The operand
|
|
305
|
+
* @returns The negated operand
|
|
306
|
+
*
|
|
307
|
+
* @example Float32.neg(-1.0f) == 1.0f
|
|
308
|
+
* @example Float32.neg(1.0f) == -1.0f
|
|
309
|
+
*
|
|
310
|
+
* @since v0.6.5
|
|
311
|
+
*/
|
|
312
|
+
@unsafe
|
|
313
|
+
provide let neg = (x: Float32) => {
|
|
314
|
+
let xv = WasmF32.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
315
|
+
let ptr = newFloat32(WasmF32.neg(xv))
|
|
316
|
+
WasmI32.toGrain(ptr): Float32
|
|
317
|
+
}
|
package/float32.md
CHANGED
|
@@ -480,3 +480,167 @@ use Float32.{ (>=) }
|
|
|
480
480
|
assert 3.0f >= 3.0f
|
|
481
481
|
```
|
|
482
482
|
|
|
483
|
+
### Float32.**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: Float32) => 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`|`Float32`|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
|
+
Float32.isNaN(NaNf)
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
```grain
|
|
515
|
+
Float32.isNaN(Infinityf) == false
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
```grain
|
|
519
|
+
Float32.isNaN(-Infinityf) == false
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
```grain
|
|
523
|
+
Float32.isNaN(0.5f) == false
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
```grain
|
|
527
|
+
Float32.isNaN(1.0f) == false
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
### Float32.**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: Float32) => 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`|`Float32`|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
|
+
Float32.isInfinite(Infinityf)
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
```grain
|
|
562
|
+
Float32.isInfinite(-Infinityf)
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
```grain
|
|
566
|
+
Float32.isInfinite(NaNf) == false
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
```grain
|
|
570
|
+
Float32.isInfinite(0.5f) == false
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
```grain
|
|
574
|
+
Float32.isInfinite(1.0f) == false
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Float32.**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: Float32) => Float32
|
|
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`|`Float32`|The operand|
|
|
595
|
+
|
|
596
|
+
Returns:
|
|
597
|
+
|
|
598
|
+
|type|description|
|
|
599
|
+
|----|-----------|
|
|
600
|
+
|`Float32`|The absolute value of the operand|
|
|
601
|
+
|
|
602
|
+
Examples:
|
|
603
|
+
|
|
604
|
+
```grain
|
|
605
|
+
Float32.abs(-1.0f) == 1.0f
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
```grain
|
|
609
|
+
Float32.abs(5.0f) == 5.0f
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
### Float32.**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: Float32) => Float32
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
Returns the negation of its operand.
|
|
624
|
+
|
|
625
|
+
Parameters:
|
|
626
|
+
|
|
627
|
+
|param|type|description|
|
|
628
|
+
|-----|----|-----------|
|
|
629
|
+
|`x`|`Float32`|The operand|
|
|
630
|
+
|
|
631
|
+
Returns:
|
|
632
|
+
|
|
633
|
+
|type|description|
|
|
634
|
+
|----|-----------|
|
|
635
|
+
|`Float32`|The negated operand|
|
|
636
|
+
|
|
637
|
+
Examples:
|
|
638
|
+
|
|
639
|
+
```grain
|
|
640
|
+
Float32.neg(-1.0f) == 1.0f
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
```grain
|
|
644
|
+
Float32.neg(1.0f) == -1.0f
|
|
645
|
+
```
|
|
646
|
+
|
package/float64.gr
CHANGED
|
@@ -24,6 +24,9 @@ use Numbers.{
|
|
|
24
24
|
coerceFloat64ToNumber as toNumber,
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
@unsafe
|
|
28
|
+
let _VALUE_OFFSET = 8n
|
|
29
|
+
|
|
27
30
|
/**
|
|
28
31
|
* Infinity represented as a Float64 value.
|
|
29
32
|
* This is an alternative to the `Infinityd` literal.
|
|
@@ -81,8 +84,8 @@ provide { fromNumber, toNumber }
|
|
|
81
84
|
*/
|
|
82
85
|
@unsafe
|
|
83
86
|
provide let (+) = (x: Float64, y: Float64) => {
|
|
84
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
85
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
87
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
88
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
86
89
|
let ptr = newFloat64(xv + yv)
|
|
87
90
|
WasmI32.toGrain(ptr): Float64
|
|
88
91
|
}
|
|
@@ -103,8 +106,8 @@ provide let (+) = (x: Float64, y: Float64) => {
|
|
|
103
106
|
*/
|
|
104
107
|
@unsafe
|
|
105
108
|
provide let (-) = (x: Float64, y: Float64) => {
|
|
106
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
107
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
109
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
110
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
108
111
|
let ptr = newFloat64(xv - yv)
|
|
109
112
|
WasmI32.toGrain(ptr): Float64
|
|
110
113
|
}
|
|
@@ -125,8 +128,8 @@ provide let (-) = (x: Float64, y: Float64) => {
|
|
|
125
128
|
*/
|
|
126
129
|
@unsafe
|
|
127
130
|
provide let (*) = (x: Float64, y: Float64) => {
|
|
128
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
129
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
131
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
132
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
130
133
|
let ptr = newFloat64(xv * yv)
|
|
131
134
|
WasmI32.toGrain(ptr): Float64
|
|
132
135
|
}
|
|
@@ -147,8 +150,8 @@ provide let (*) = (x: Float64, y: Float64) => {
|
|
|
147
150
|
*/
|
|
148
151
|
@unsafe
|
|
149
152
|
provide let (/) = (x: Float64, y: Float64) => {
|
|
150
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
151
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
153
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
154
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
152
155
|
let ptr = newFloat64(xv / yv)
|
|
153
156
|
WasmI32.toGrain(ptr): Float64
|
|
154
157
|
}
|
|
@@ -169,8 +172,8 @@ provide let (/) = (x: Float64, y: Float64) => {
|
|
|
169
172
|
*/
|
|
170
173
|
@unsafe
|
|
171
174
|
provide let (<) = (x: Float64, y: Float64) => {
|
|
172
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
173
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
175
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
176
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
174
177
|
xv < yv
|
|
175
178
|
}
|
|
176
179
|
|
|
@@ -190,8 +193,8 @@ provide let (<) = (x: Float64, y: Float64) => {
|
|
|
190
193
|
*/
|
|
191
194
|
@unsafe
|
|
192
195
|
provide let (>) = (x: Float64, y: Float64) => {
|
|
193
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
194
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
196
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
197
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
195
198
|
xv > yv
|
|
196
199
|
}
|
|
197
200
|
|
|
@@ -215,8 +218,8 @@ provide let (>) = (x: Float64, y: Float64) => {
|
|
|
215
218
|
*/
|
|
216
219
|
@unsafe
|
|
217
220
|
provide let (<=) = (x: Float64, y: Float64) => {
|
|
218
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
219
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
221
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
222
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
220
223
|
xv <= yv
|
|
221
224
|
}
|
|
222
225
|
|
|
@@ -240,7 +243,75 @@ provide let (<=) = (x: Float64, y: Float64) => {
|
|
|
240
243
|
*/
|
|
241
244
|
@unsafe
|
|
242
245
|
provide let (>=) = (x: Float64, y: Float64) => {
|
|
243
|
-
let xv = WasmF64.load(WasmI32.fromGrain(x),
|
|
244
|
-
let yv = WasmF64.load(WasmI32.fromGrain(y),
|
|
246
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
247
|
+
let yv = WasmF64.load(WasmI32.fromGrain(y), _VALUE_OFFSET)
|
|
245
248
|
xv >= yv
|
|
246
249
|
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Checks if the value is a float NaN value (Not A Number).
|
|
253
|
+
*
|
|
254
|
+
* @param x: The value to check
|
|
255
|
+
* @returns `true` if the value is NaN, otherwise `false`
|
|
256
|
+
*
|
|
257
|
+
* @example Float64.isNaN(NaNd)
|
|
258
|
+
* @example Float64.isNaN(Infinityd) == false
|
|
259
|
+
* @example Float64.isNaN(-Infinityd) == false
|
|
260
|
+
* @example Float64.isNaN(0.5d) == false
|
|
261
|
+
* @example Float64.isNaN(1.0d) == false
|
|
262
|
+
*
|
|
263
|
+
* @since v0.6.5
|
|
264
|
+
*/
|
|
265
|
+
provide let isNaN = (x: Float64) => x != x
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Checks if a float is infinite, that is either of positive or negative infinity.
|
|
269
|
+
*
|
|
270
|
+
* @param x: The value to check
|
|
271
|
+
* @returns `true` if the value is infinite or `false` otherwise
|
|
272
|
+
*
|
|
273
|
+
* @example Float64.isInfinite(Infinityd)
|
|
274
|
+
* @example Float64.isInfinite(-Infinityd)
|
|
275
|
+
* @example Float64.isInfinite(NaNd) == false
|
|
276
|
+
* @example Float64.isInfinite(0.5d) == false
|
|
277
|
+
* @example Float64.isInfinite(1.0d) == false
|
|
278
|
+
*
|
|
279
|
+
* @since v0.6.5
|
|
280
|
+
*/
|
|
281
|
+
provide let isInfinite = (x: Float64) => x == Infinityd || x == -Infinityd
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Returns the absolute value. That is, it returns `x` if `x` is positive or zero and the negation of `x` if `x` is negative.
|
|
285
|
+
*
|
|
286
|
+
* @param x: The operand
|
|
287
|
+
* @returns The absolute value of the operand
|
|
288
|
+
*
|
|
289
|
+
* @example Float64.abs(-1.0d) == 1.0d
|
|
290
|
+
* @example Float64.abs(5.0d) == 5.0d
|
|
291
|
+
*
|
|
292
|
+
* @since v0.6.5
|
|
293
|
+
*/
|
|
294
|
+
@unsafe
|
|
295
|
+
provide let abs = (x: Float64) => {
|
|
296
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
297
|
+
let ptr = newFloat64(WasmF64.abs(xv))
|
|
298
|
+
WasmI32.toGrain(ptr): Float64
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Returns the negation of its operand.
|
|
303
|
+
*
|
|
304
|
+
* @param x: The operand
|
|
305
|
+
* @returns The negated operand
|
|
306
|
+
*
|
|
307
|
+
* @example Float64.neg(-1.0d) == 1.0d
|
|
308
|
+
* @example Float64.neg(1.0d) == -1.0d
|
|
309
|
+
*
|
|
310
|
+
* @since v0.6.5
|
|
311
|
+
*/
|
|
312
|
+
@unsafe
|
|
313
|
+
provide let neg = (x: Float64) => {
|
|
314
|
+
let xv = WasmF64.load(WasmI32.fromGrain(x), _VALUE_OFFSET)
|
|
315
|
+
let ptr = newFloat64(WasmF64.neg(xv))
|
|
316
|
+
WasmI32.toGrain(ptr): Float64
|
|
317
|
+
}
|