@grain/stdlib 0.4.6 → 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.
Files changed (85) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/array.gr +18 -18
  3. package/array.md +18 -18
  4. package/bigint.gr +497 -0
  5. package/bigint.md +811 -0
  6. package/buffer.gr +59 -223
  7. package/buffer.md +24 -17
  8. package/bytes.gr +100 -202
  9. package/bytes.md +19 -0
  10. package/char.gr +63 -133
  11. package/exception.gr +28 -2
  12. package/exception.md +43 -0
  13. package/float32.gr +76 -95
  14. package/float32.md +69 -30
  15. package/float64.gr +81 -95
  16. package/float64.md +69 -30
  17. package/hash.gr +37 -37
  18. package/int32.gr +152 -198
  19. package/int32.md +104 -0
  20. package/int64.gr +151 -197
  21. package/int64.md +104 -0
  22. package/list.gr +467 -70
  23. package/list.md +1141 -0
  24. package/map.gr +192 -7
  25. package/map.md +525 -0
  26. package/number.gr +111 -54
  27. package/number.md +100 -3
  28. package/option.md +1 -1
  29. package/package.json +3 -3
  30. package/pervasives.gr +499 -59
  31. package/pervasives.md +1116 -0
  32. package/queue.gr +4 -0
  33. package/queue.md +10 -0
  34. package/random.gr +196 -0
  35. package/random.md +179 -0
  36. package/regex.gr +1833 -842
  37. package/regex.md +11 -11
  38. package/result.md +1 -1
  39. package/runtime/bigint.gr +2045 -0
  40. package/runtime/bigint.md +326 -0
  41. package/runtime/dataStructures.gr +99 -278
  42. package/runtime/dataStructures.md +391 -0
  43. package/runtime/debug.md +6 -0
  44. package/runtime/equal.gr +5 -23
  45. package/runtime/equal.md +6 -0
  46. package/runtime/exception.md +30 -0
  47. package/runtime/gc.gr +20 -3
  48. package/runtime/gc.md +36 -0
  49. package/runtime/malloc.gr +13 -11
  50. package/runtime/malloc.md +55 -0
  51. package/runtime/numberUtils.gr +91 -41
  52. package/runtime/numberUtils.md +54 -0
  53. package/runtime/numbers.gr +1049 -391
  54. package/runtime/numbers.md +300 -0
  55. package/runtime/string.gr +136 -230
  56. package/runtime/string.md +24 -0
  57. package/runtime/stringUtils.gr +58 -38
  58. package/runtime/stringUtils.md +6 -0
  59. package/runtime/unsafe/constants.gr +17 -0
  60. package/runtime/unsafe/constants.md +72 -0
  61. package/runtime/unsafe/conv.md +71 -0
  62. package/runtime/unsafe/errors.md +204 -0
  63. package/runtime/unsafe/memory.md +54 -0
  64. package/runtime/unsafe/printWasm.md +24 -0
  65. package/runtime/unsafe/tags.gr +9 -8
  66. package/runtime/unsafe/tags.md +120 -0
  67. package/runtime/unsafe/wasmf32.md +168 -0
  68. package/runtime/unsafe/wasmf64.md +168 -0
  69. package/runtime/unsafe/wasmi32.md +282 -0
  70. package/runtime/unsafe/wasmi64.md +300 -0
  71. package/runtime/utils/printing.gr +62 -0
  72. package/runtime/utils/printing.md +18 -0
  73. package/runtime/wasi.gr +1 -1
  74. package/runtime/wasi.md +839 -0
  75. package/set.gr +17 -8
  76. package/set.md +24 -21
  77. package/stack.gr +3 -3
  78. package/stack.md +4 -6
  79. package/string.gr +194 -329
  80. package/string.md +3 -3
  81. package/sys/file.gr +245 -429
  82. package/sys/process.gr +27 -45
  83. package/sys/random.gr +47 -16
  84. package/sys/random.md +38 -0
  85. package/sys/time.gr +11 -27
package/char.gr CHANGED
@@ -9,11 +9,12 @@
9
9
  */
10
10
 
11
11
  import WasmI32 from "runtime/unsafe/wasmi32"
12
- import Memory from "runtime/unsafe/memory"
13
12
  import Errors from "runtime/unsafe/errors"
13
+ import Tags from "runtime/unsafe/tags"
14
14
  import {
15
15
  tagSimpleNumber,
16
- allocateChar,
16
+ tagChar,
17
+ untagChar,
17
18
  allocateString,
18
19
  } from "runtime/dataStructures"
19
20
 
@@ -58,71 +59,13 @@ export let isValid = charCode => {
58
59
  *
59
60
  * @since 0.3.0
60
61
  */
61
- @disableGC
62
- export let rec code = (char: Char) => {
63
- // Algorithm from https://encoding.spec.whatwg.org/#utf-8-decoder
62
+ @unsafe
63
+ export let code = (char: Char) => {
64
+ let usv = untagChar(char)
64
65
 
65
- let char = WasmI32.fromGrain(char)
66
-
67
- let (+) = WasmI32.add
68
- let (==) = WasmI32.eq
69
- let (>=) = WasmI32.geU
70
- let (<=) = WasmI32.leU
71
- let (<<) = WasmI32.shl
72
- let (&) = WasmI32.and
73
- let (|) = WasmI32.or
74
-
75
- let mut codePoint = 0n
76
- let mut bytesSeen = 0n
77
- let mut bytesNeeded = 0n
78
- let mut lowerBoundary = 0x80n
79
- let mut upperBoundary = 0xBFn
80
-
81
- let mut offset = 0n
82
-
83
- let mut result = 0n
84
-
85
- while (true) {
86
- let byte = WasmI32.load8U(char + offset, 4n)
87
- offset += 1n
88
- if (bytesNeeded == 0n) {
89
- if (byte >= 0x00n && byte <= 0x7Fn) {
90
- result = byte
91
- break
92
- } else if (byte >= 0xC2n && byte <= 0xDFn) {
93
- bytesNeeded = 1n
94
- codePoint = byte & 0x1Fn
95
- } else if (byte >= 0xE0n && byte <= 0xEFn) {
96
- if (byte == 0xE0n) lowerBoundary = 0xA0n
97
- if (byte == 0xEDn) upperBoundary = 0x9Fn
98
- bytesNeeded = 2n
99
- codePoint = byte & 0xFn
100
- } else if (byte >= 0xF0n && byte <= 0xF4n) {
101
- if (byte == 0xF0n) lowerBoundary = 0x90n
102
- if (byte == 0xF4n) upperBoundary = 0x8Fn
103
- bytesNeeded = 3n
104
- codePoint = byte & 0x7n
105
- } else {
106
- throw MalformedUtf8
107
- }
108
- continue
109
- }
110
- if (!(lowerBoundary <= byte && byte <= upperBoundary)) {
111
- throw MalformedUtf8
112
- }
113
- lowerBoundary = 0x80n
114
- upperBoundary = 0xBFn
115
- codePoint = codePoint << 6n | byte & 0x3Fn
116
- bytesSeen += 1n
117
- if (bytesSeen == bytesNeeded) {
118
- result = codePoint
119
- break
120
- }
121
- }
122
-
123
- Memory.decRef(char)
124
- Memory.decRef(WasmI32.fromGrain(code))
125
- tagSimpleNumber(result)
66
+ // This could save an instruction by combining the two tagging operations,
67
+ // though we stick with tagSimpleNumber for simplicity.
68
+ tagSimpleNumber(usv)
126
69
  }
127
70
 
128
71
  /**
@@ -134,62 +77,26 @@ export let rec code = (char: Char) => {
134
77
  *
135
78
  * @since 0.3.0
136
79
  */
137
- @disableGC
138
- export let rec fromCode = (usv: Number) => {
139
- // Algorithm from https://encoding.spec.whatwg.org/#utf-8-encoder
140
-
141
- let (+) = WasmI32.add
80
+ @unsafe
81
+ export let fromCode = (usv: Number) => {
142
82
  let (-) = WasmI32.sub
143
- let (*) = WasmI32.mul
144
- let (==) = WasmI32.eq
145
- let (>) = WasmI32.gtU
146
- let (<=) = WasmI32.leU
147
- let (<) = WasmI32.ltU
148
- let (>>>) = WasmI32.shrU
149
- let (&) = WasmI32.and
150
- let (|) = WasmI32.or
83
+ let (<<) = WasmI32.shl
151
84
 
152
- let usv = WasmI32.fromGrain(usv)
153
- if ((usv & 1n) == 0n) {
85
+ if (!isValid(usv)) {
154
86
  throw InvalidArgument("Invalid character code")
155
87
  }
156
88
 
157
- let usv = usv >>> 1n
158
- let result = if (usv < 0x80n) {
159
- let char = allocateChar()
160
- WasmI32.store8(char, usv, 4n)
161
- WasmI32.toGrain(char): Char
162
- } else {
163
- let mut count = 0n
164
- let mut offset = 0n
165
- if (usv <= 0x07FFn) {
166
- count = 1n
167
- offset = 0xC0n
168
- } else if (usv <= 0xFFFFn) {
169
- count = 2n
170
- offset = 0xE0n
171
- } else {
172
- count = 3n
173
- offset = 0xF0n
174
- }
175
- let char = allocateChar()
176
- WasmI32.store8(char, (usv >>> 6n * count) + offset, 4n)
177
-
178
- let mut n = 0n
179
- while (count > 0n) {
180
- n += 1n
181
- let temp = usv >>> 6n * (count - 1n)
182
- WasmI32.store8(char + n, 0x80n | temp & 0x3Fn, 4n)
183
- count -= 1n
184
- }
89
+ // usv is now guaranteed to be a simple number
90
+ let usv = WasmI32.fromGrain(usv)
185
91
 
186
- WasmI32.toGrain(char): Char
187
- }
92
+ // Here we use a math trick to avoid fully untagging and retagging.
93
+ // Simple numbers are represented as 2n + 1 and chars are represented as
94
+ // 8n + 2. Quick reminder that shifting left is the equivalent of multiplying
95
+ // by 2, and that _GRAIN_CHAR_TAG_TYPE is equal to 2:
96
+ // 4(2n + 1) - 2 = 8n + 2
97
+ let char = (usv << 2n) - Tags._GRAIN_CHAR_TAG_TYPE
188
98
 
189
- // We've asserted that the original `code` was a stack allocated number so
190
- // no need to decRef it
191
- Memory.decRef(WasmI32.fromGrain(fromCode))
192
- result
99
+ WasmI32.toGrain(char): Char
193
100
  }
194
101
 
195
102
  /**
@@ -240,27 +147,50 @@ export let pred = char => {
240
147
  *
241
148
  * @since 0.3.0
242
149
  */
243
- @disableGC
244
- export let rec toString = (char: Char) => {
150
+ @unsafe
151
+ export let toString = (char: Char) => {
245
152
  let (+) = WasmI32.add
153
+ let (-) = WasmI32.sub
154
+ let (*) = WasmI32.mul
246
155
  let (&) = WasmI32.and
247
- let (==) = WasmI32.eq
156
+ let (|) = WasmI32.or
157
+ let (>>>) = WasmI32.shrU
158
+ let (<) = WasmI32.ltU
159
+ let (>) = WasmI32.gtU
160
+ let (<=) = WasmI32.leU
161
+
162
+ let usv = untagChar(char)
248
163
 
249
- let char = WasmI32.fromGrain(char)
250
- let byte = WasmI32.load8U(char, 4n)
251
- let n = if ((byte & 0x80n) == 0x00n) {
252
- 1n
253
- } else if ((byte & 0xF0n) == 0xF0n) {
254
- 4n
255
- } else if ((byte & 0xE0n) == 0xE0n) {
256
- 3n
164
+ let result = if (usv < 0x80n) {
165
+ let string = allocateString(1n)
166
+ WasmI32.store8(string, usv, 8n)
167
+ WasmI32.toGrain(string): String
257
168
  } else {
258
- 2n
169
+ let mut count = 0n
170
+ let mut offset = 0n
171
+ if (usv <= 0x07FFn) {
172
+ count = 1n
173
+ offset = 0xC0n
174
+ } else if (usv <= 0xFFFFn) {
175
+ count = 2n
176
+ offset = 0xE0n
177
+ } else {
178
+ count = 3n
179
+ offset = 0xF0n
180
+ }
181
+ let string = allocateString(count + 1n)
182
+ WasmI32.store8(string, (usv >>> 6n * count) + offset, 8n)
183
+
184
+ let mut n = 0n
185
+ while (count > 0n) {
186
+ n += 1n
187
+ let temp = usv >>> 6n * (count - 1n)
188
+ WasmI32.store8(string + n, 0x80n | temp & 0x3Fn, 8n)
189
+ count -= 1n
190
+ }
191
+
192
+ WasmI32.toGrain(string): String
259
193
  }
260
- let str = allocateString(n)
261
- Memory.copy(str + 8n, char + 4n, n)
262
- let ret = WasmI32.toGrain(str): String
263
- Memory.decRef(WasmI32.fromGrain(char))
264
- Memory.decRef(WasmI32.fromGrain(toString))
265
- ret
194
+
195
+ result
266
196
  }
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 = (f: Exception -> Option<String>) => {
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((f, Exception.printers))
34
+ Exception.printers = WasmI32.fromGrain((printer, Exception.printers))
9
35
  Memory.decRef(WasmI32.fromGrain(registerPrinter))
10
36
  void
11
37
  }
package/exception.md ADDED
@@ -0,0 +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
+
22
+ ### Exception.**registerPrinter**
23
+
24
+ <details disabled>
25
+ <summary tabindex="-1">Added in <code>0.3.0</code></summary>
26
+ No other changes yet.
27
+ </details>
28
+
29
+ ```grain
30
+ registerPrinter : (Exception -> Option<String>) -> Void
31
+ ```
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
@@ -6,16 +6,63 @@
6
6
  */
7
7
  import WasmI32 from "runtime/unsafe/wasmi32"
8
8
  import WasmF32 from "runtime/unsafe/wasmf32"
9
- import Memory from "runtime/unsafe/memory"
10
- import {
11
- newFloat32
12
- } from "runtime/dataStructures"
9
+ import { newFloat32 } from "runtime/dataStructures"
13
10
 
14
11
  import {
15
12
  coerceNumberToFloat32 as fromNumber,
16
- coerceFloat32ToNumber as toNumber
13
+ coerceFloat32ToNumber as toNumber,
17
14
  } from "runtime/numbers"
18
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
19
66
  /**
20
67
  * @section Conversions: Functions for converting between Numbers and the Float32 type.
21
68
  */
@@ -53,16 +100,12 @@ export toNumber
53
100
  *
54
101
  * @since v0.2.0
55
102
  */
56
- @disableGC
57
- export let rec add = (x: Float32, y: Float32) => {
103
+ @unsafe
104
+ export let add = (x: Float32, y: Float32) => {
58
105
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
59
106
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
60
107
  let ptr = newFloat32(WasmF32.add(xv, yv))
61
- let ret = WasmI32.toGrain(ptr) : Float32
62
- Memory.decRef(WasmI32.fromGrain(x))
63
- Memory.decRef(WasmI32.fromGrain(y))
64
- Memory.decRef(WasmI32.fromGrain(add))
65
- ret
108
+ WasmI32.toGrain(ptr): Float32
66
109
  }
67
110
 
68
111
  /**
@@ -74,16 +117,12 @@ export let rec add = (x: Float32, y: Float32) => {
74
117
  *
75
118
  * @since v0.2.0
76
119
  */
77
- @disableGC
78
- export let rec sub = (x: Float32, y: Float32) => {
120
+ @unsafe
121
+ export let sub = (x: Float32, y: Float32) => {
79
122
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
80
123
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
81
124
  let ptr = newFloat32(WasmF32.sub(xv, yv))
82
- let ret = WasmI32.toGrain(ptr) : Float32
83
- Memory.decRef(WasmI32.fromGrain(x))
84
- Memory.decRef(WasmI32.fromGrain(y))
85
- Memory.decRef(WasmI32.fromGrain(sub))
86
- ret
125
+ WasmI32.toGrain(ptr): Float32
87
126
  }
88
127
 
89
128
  /**
@@ -95,16 +134,12 @@ export let rec sub = (x: Float32, y: Float32) => {
95
134
  *
96
135
  * @since v0.2.0
97
136
  */
98
- @disableGC
99
- export let rec mul = (x: Float32, y: Float32) => {
137
+ @unsafe
138
+ export let mul = (x: Float32, y: Float32) => {
100
139
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
101
140
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
102
141
  let ptr = newFloat32(WasmF32.mul(xv, yv))
103
- let ret = WasmI32.toGrain(ptr) : Float32
104
- Memory.decRef(WasmI32.fromGrain(x))
105
- Memory.decRef(WasmI32.fromGrain(y))
106
- Memory.decRef(WasmI32.fromGrain(mul))
107
- ret
142
+ WasmI32.toGrain(ptr): Float32
108
143
  }
109
144
 
110
145
  /**
@@ -116,16 +151,12 @@ export let rec mul = (x: Float32, y: Float32) => {
116
151
  *
117
152
  * @since v0.2.0
118
153
  */
119
- @disableGC
120
- export let rec div = (x: Float32, y: Float32) => {
154
+ @unsafe
155
+ export let div = (x: Float32, y: Float32) => {
121
156
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
122
157
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
123
158
  let ptr = newFloat32(WasmF32.div(xv, yv))
124
- let ret = WasmI32.toGrain(ptr) : Float32
125
- Memory.decRef(WasmI32.fromGrain(x))
126
- Memory.decRef(WasmI32.fromGrain(y))
127
- Memory.decRef(WasmI32.fromGrain(div))
128
- ret
159
+ WasmI32.toGrain(ptr): Float32
129
160
  }
130
161
 
131
162
  /**
@@ -141,15 +172,11 @@ export let rec div = (x: Float32, y: Float32) => {
141
172
  *
142
173
  * @since v0.2.0
143
174
  */
144
- @disableGC
145
- export let rec lt = (x: Float32, y: Float32) => {
175
+ @unsafe
176
+ export let lt = (x: Float32, y: Float32) => {
146
177
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
147
178
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
148
- let ret = WasmF32.lt(xv, yv)
149
- Memory.decRef(WasmI32.fromGrain(x))
150
- Memory.decRef(WasmI32.fromGrain(y))
151
- Memory.decRef(WasmI32.fromGrain(lt))
152
- ret
179
+ WasmF32.lt(xv, yv)
153
180
  }
154
181
 
155
182
  /**
@@ -161,15 +188,11 @@ export let rec lt = (x: Float32, y: Float32) => {
161
188
  *
162
189
  * @since v0.2.0
163
190
  */
164
- @disableGC
165
- export let rec gt = (x: Float32, y: Float32) => {
191
+ @unsafe
192
+ export let gt = (x: Float32, y: Float32) => {
166
193
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
167
194
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
168
- let ret = WasmF32.gt(xv, yv)
169
- Memory.decRef(WasmI32.fromGrain(x))
170
- Memory.decRef(WasmI32.fromGrain(y))
171
- Memory.decRef(WasmI32.fromGrain(gt))
172
- ret
195
+ WasmF32.gt(xv, yv)
173
196
  }
174
197
 
175
198
  /**
@@ -181,15 +204,11 @@ export let rec gt = (x: Float32, y: Float32) => {
181
204
  *
182
205
  * @since v0.2.0
183
206
  */
184
- @disableGC
185
- export let rec lte = (x: Float32, y: Float32) => {
207
+ @unsafe
208
+ export let lte = (x: Float32, y: Float32) => {
186
209
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
187
210
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
188
- let ret = WasmF32.le(xv, yv)
189
- Memory.decRef(WasmI32.fromGrain(x))
190
- Memory.decRef(WasmI32.fromGrain(y))
191
- Memory.decRef(WasmI32.fromGrain(lte))
192
- ret
211
+ WasmF32.le(xv, yv)
193
212
  }
194
213
 
195
214
  /**
@@ -201,47 +220,9 @@ export let rec lte = (x: Float32, y: Float32) => {
201
220
  *
202
221
  * @since v0.2.0
203
222
  */
204
- @disableGC
205
- export let rec gte = (x: Float32, y: Float32) => {
223
+ @unsafe
224
+ export let gte = (x: Float32, y: Float32) => {
206
225
  let xv = WasmF32.load(WasmI32.fromGrain(x), 8n)
207
226
  let yv = WasmF32.load(WasmI32.fromGrain(y), 8n)
208
- let ret = WasmF32.ge(xv, yv)
209
- Memory.decRef(WasmI32.fromGrain(x))
210
- Memory.decRef(WasmI32.fromGrain(y))
211
- Memory.decRef(WasmI32.fromGrain(gte))
212
- ret
227
+ WasmF32.ge(xv, yv)
213
228
  }
214
-
215
- /**
216
- * @section Constants: Float32 constant values.
217
- */
218
-
219
- @disableGC
220
- let rec makeInfinity = () => {
221
- let ptr = newFloat32(WasmF32.reinterpretI32(0b01111111100000000000000000000000n))
222
- let ret = WasmI32.toGrain(ptr) : Float32
223
- Memory.decRef(WasmI32.fromGrain(makeInfinity))
224
- ret
225
- }
226
-
227
- /**
228
- * Infinity represented as a Float32 value.
229
- *
230
- * @since v0.4.0
231
- */
232
- export let infinity = makeInfinity()
233
-
234
- @disableGC
235
- let rec makeNaN = () => {
236
- let ptr = newFloat32(WasmF32.reinterpretI32(0b01111111100000000000000000000001n))
237
- let ret = WasmI32.toGrain(ptr) : Float32
238
- Memory.decRef(WasmI32.fromGrain(makeNaN))
239
- ret
240
- }
241
-
242
- /**
243
- * NaN (Not a Number) represented as a Float32 value.
244
- *
245
- * @since v0.4.0
246
- */
247
- export let nan = makeNaN()
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
-