redscript-mc 3.0.1 → 3.0.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/.github/workflows/ci.yml +1 -0
- package/README.md +119 -313
- package/README.zh.md +118 -314
- package/ROADMAP.md +5 -5
- package/dist/data/impl_test/function/counter/get.mcfunction +5 -0
- package/dist/data/impl_test/function/counter/inc.mcfunction +7 -0
- package/dist/data/impl_test/function/counter/new.mcfunction +4 -0
- package/dist/data/impl_test/function/load.mcfunction +1 -0
- package/dist/data/impl_test/function/test_impl.mcfunction +10 -0
- package/dist/data/minecraft/tags/function/load.json +5 -0
- package/dist/data/playground/function/load.mcfunction +1 -0
- package/dist/data/playground/function/start.mcfunction +4 -0
- package/dist/data/playground/function/start__say_macro_t1.mcfunction +1 -0
- package/dist/data/playground/function/stop.mcfunction +5 -0
- package/dist/data/playground/function/stop__say_macro_t0.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/__queue_append_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_peek_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/__queue_size_raw_apply.mcfunction +4 -0
- package/dist/data/stdlib_queue8_test/function/load.mcfunction +1 -0
- package/dist/data/stdlib_queue8_test/function/queue_clear.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__merge_1.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_empty__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__merge_1.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/queue_peek__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__merge_1.mcfunction +15 -0
- package/dist/data/stdlib_queue8_test/function/queue_pop__then_0.mcfunction +5 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_11.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_push__const_22.mcfunction +6 -0
- package/dist/data/stdlib_queue8_test/function/queue_size.mcfunction +13 -0
- package/dist/data/stdlib_queue8_test/function/test_queue_push_and_size.mcfunction +13 -0
- package/dist/data/test/function/load.mcfunction +1 -0
- package/dist/data/test/function/say_at.mcfunction +6 -0
- package/dist/data/test/function/test.mcfunction +4 -0
- package/dist/pack.mcmeta +6 -0
- package/dist/package.json +1 -1
- package/dist/src/__tests__/formatter-extra.test.d.ts +7 -0
- package/dist/src/__tests__/formatter-extra.test.js +123 -0
- package/dist/src/__tests__/global-vars.test.d.ts +13 -0
- package/dist/src/__tests__/global-vars.test.js +156 -0
- package/dist/src/__tests__/lint/new-rules.test.d.ts +9 -0
- package/dist/src/__tests__/lint/new-rules.test.js +402 -0
- package/dist/src/__tests__/lsp-rename.test.d.ts +8 -0
- package/dist/src/__tests__/lsp-rename.test.js +157 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.d.ts +11 -0
- package/dist/src/__tests__/mc-integration/say-fstring.test.js +220 -0
- package/dist/src/__tests__/mc-integration/stdlib-coverage-2.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-3.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-4.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-5.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-6.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-7.test.js +1 -1
- package/dist/src/__tests__/mc-integration/stdlib-coverage-8.test.js +1 -1
- package/dist/src/__tests__/mc-syntax.test.js +4 -1
- package/dist/src/__tests__/monomorphize-coverage.test.d.ts +9 -0
- package/dist/src/__tests__/monomorphize-coverage.test.js +204 -0
- package/dist/src/__tests__/optimizer-cse.test.d.ts +7 -0
- package/dist/src/__tests__/optimizer-cse.test.js +226 -0
- package/dist/src/__tests__/parser.test.js +4 -13
- package/dist/src/__tests__/repl-server-extra.test.js +6 -7
- package/dist/src/__tests__/repl-server.test.js +5 -7
- package/dist/src/__tests__/stdlib/queue.test.js +6 -6
- package/dist/src/cli.js +0 -0
- package/dist/src/lexer/index.js +2 -1
- package/dist/src/lint/index.d.ts +12 -5
- package/dist/src/lint/index.js +730 -5
- package/dist/src/lsp/main.js +0 -0
- package/dist/src/mc-test/client.d.ts +21 -0
- package/dist/src/mc-test/client.js +34 -0
- package/dist/src/mir/lower.js +108 -6
- package/dist/src/optimizer/interprocedural.js +37 -2
- package/dist/src/parser/decl-parser.d.ts +19 -0
- package/dist/src/parser/decl-parser.js +323 -0
- package/dist/src/parser/expr-parser.d.ts +46 -0
- package/dist/src/parser/expr-parser.js +759 -0
- package/dist/src/parser/index.d.ts +8 -129
- package/dist/src/parser/index.js +13 -2262
- package/dist/src/parser/stmt-parser.d.ts +28 -0
- package/dist/src/parser/stmt-parser.js +577 -0
- package/dist/src/parser/type-parser.d.ts +20 -0
- package/dist/src/parser/type-parser.js +257 -0
- package/dist/src/parser/utils.d.ts +34 -0
- package/dist/src/parser/utils.js +141 -0
- package/docs/dev/README-mc-integration-tests.md +141 -0
- package/docs/lint-rules.md +162 -0
- package/docs/stdlib/bigint.md +2 -0
- package/editors/vscode/README.md +63 -41
- package/editors/vscode/out/extension.js +1881 -1776
- package/editors/vscode/out/lsp-server.js +4257 -3651
- package/editors/vscode/package-lock.json +3 -3
- package/editors/vscode/package.json +1 -1
- package/examples/loops-demo.mcrs +87 -0
- package/package.json +1 -1
- package/redscript-docs/docs/en/stdlib/advanced.md +629 -0
- package/redscript-docs/docs/en/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/en/stdlib/bits.md +292 -0
- package/redscript-docs/docs/en/stdlib/bossbar.md +177 -0
- package/redscript-docs/docs/en/stdlib/calculus.md +289 -0
- package/redscript-docs/docs/en/stdlib/color.md +353 -0
- package/redscript-docs/docs/en/stdlib/combat.md +88 -0
- package/redscript-docs/docs/en/stdlib/cooldown.md +82 -0
- package/redscript-docs/docs/en/stdlib/dialog.md +155 -0
- package/redscript-docs/docs/en/stdlib/easing.md +558 -0
- package/redscript-docs/docs/en/stdlib/ecs.md +475 -0
- package/redscript-docs/docs/en/stdlib/effects.md +324 -0
- package/redscript-docs/docs/en/stdlib/events.md +3 -0
- package/redscript-docs/docs/en/stdlib/expr.md +45 -0
- package/redscript-docs/docs/en/stdlib/fft.md +141 -0
- package/redscript-docs/docs/en/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/en/stdlib/graph.md +259 -0
- package/redscript-docs/docs/en/stdlib/heap.md +185 -0
- package/redscript-docs/docs/en/stdlib/interactions.md +179 -0
- package/redscript-docs/docs/en/stdlib/inventory.md +97 -0
- package/redscript-docs/docs/en/stdlib/linalg.md +557 -0
- package/redscript-docs/docs/en/stdlib/list.md +559 -0
- package/redscript-docs/docs/en/stdlib/map.md +140 -0
- package/redscript-docs/docs/en/stdlib/math.md +193 -0
- package/redscript-docs/docs/en/stdlib/math_hp.md +149 -0
- package/redscript-docs/docs/en/stdlib/matrix.md +403 -0
- package/redscript-docs/docs/en/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/en/stdlib/noise.md +244 -0
- package/redscript-docs/docs/en/stdlib/ode.md +253 -0
- package/redscript-docs/docs/en/stdlib/parabola.md +342 -0
- package/redscript-docs/docs/en/stdlib/particles.md +311 -0
- package/redscript-docs/docs/en/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/en/stdlib/physics.md +493 -0
- package/redscript-docs/docs/en/stdlib/player.md +78 -0
- package/redscript-docs/docs/en/stdlib/quaternion.md +673 -0
- package/redscript-docs/docs/en/stdlib/queue.md +134 -0
- package/redscript-docs/docs/en/stdlib/random.md +223 -0
- package/redscript-docs/docs/en/stdlib/result.md +143 -0
- package/redscript-docs/docs/en/stdlib/scheduler.md +183 -0
- package/redscript-docs/docs/en/stdlib/set_int.md +190 -0
- package/redscript-docs/docs/en/stdlib/sets.md +101 -0
- package/redscript-docs/docs/en/stdlib/signal.md +400 -0
- package/redscript-docs/docs/en/stdlib/sort.md +104 -0
- package/redscript-docs/docs/en/stdlib/spawn.md +147 -0
- package/redscript-docs/docs/en/stdlib/state.md +142 -0
- package/redscript-docs/docs/en/stdlib/strings.md +154 -0
- package/redscript-docs/docs/en/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/en/stdlib/teams.md +153 -0
- package/redscript-docs/docs/en/stdlib/timer.md +246 -0
- package/redscript-docs/docs/en/stdlib/vec.md +158 -0
- package/redscript-docs/docs/en/stdlib/world.md +298 -0
- package/redscript-docs/docs/zh/stdlib/advanced.md +615 -0
- package/redscript-docs/docs/zh/stdlib/bigint.md +316 -0
- package/redscript-docs/docs/zh/stdlib/bits.md +292 -0
- package/redscript-docs/docs/zh/stdlib/bossbar.md +170 -0
- package/redscript-docs/docs/zh/stdlib/calculus.md +287 -0
- package/redscript-docs/docs/zh/stdlib/color.md +353 -0
- package/redscript-docs/docs/zh/stdlib/combat.md +88 -0
- package/redscript-docs/docs/zh/stdlib/cooldown.md +84 -0
- package/redscript-docs/docs/zh/stdlib/dialog.md +152 -0
- package/redscript-docs/docs/zh/stdlib/easing.md +558 -0
- package/redscript-docs/docs/zh/stdlib/ecs.md +472 -0
- package/redscript-docs/docs/zh/stdlib/effects.md +324 -0
- package/redscript-docs/docs/zh/stdlib/events.md +3 -0
- package/redscript-docs/docs/zh/stdlib/expr.md +37 -0
- package/redscript-docs/docs/zh/stdlib/fft.md +128 -0
- package/redscript-docs/docs/zh/stdlib/geometry.md +430 -0
- package/redscript-docs/docs/zh/stdlib/graph.md +259 -0
- package/redscript-docs/docs/zh/stdlib/heap.md +185 -0
- package/redscript-docs/docs/zh/stdlib/interactions.md +160 -0
- package/redscript-docs/docs/zh/stdlib/inventory.md +94 -0
- package/redscript-docs/docs/zh/stdlib/linalg.md +543 -0
- package/redscript-docs/docs/zh/stdlib/list.md +561 -0
- package/redscript-docs/docs/zh/stdlib/map.md +132 -0
- package/redscript-docs/docs/zh/stdlib/math.md +193 -0
- package/redscript-docs/docs/zh/stdlib/math_hp.md +143 -0
- package/redscript-docs/docs/zh/stdlib/matrix.md +396 -0
- package/redscript-docs/docs/zh/stdlib/mobs.md +965 -0
- package/redscript-docs/docs/zh/stdlib/noise.md +244 -0
- package/redscript-docs/docs/zh/stdlib/ode.md +243 -0
- package/redscript-docs/docs/zh/stdlib/parabola.md +337 -0
- package/redscript-docs/docs/zh/stdlib/particles.md +307 -0
- package/redscript-docs/docs/zh/stdlib/pathfind.md +255 -0
- package/redscript-docs/docs/zh/stdlib/physics.md +493 -0
- package/redscript-docs/docs/zh/stdlib/player.md +78 -0
- package/redscript-docs/docs/zh/stdlib/quaternion.md +669 -0
- package/redscript-docs/docs/zh/stdlib/queue.md +124 -0
- package/redscript-docs/docs/zh/stdlib/random.md +222 -0
- package/redscript-docs/docs/zh/stdlib/result.md +147 -0
- package/redscript-docs/docs/zh/stdlib/scheduler.md +173 -0
- package/redscript-docs/docs/zh/stdlib/set_int.md +180 -0
- package/redscript-docs/docs/zh/stdlib/sets.md +107 -0
- package/redscript-docs/docs/zh/stdlib/signal.md +373 -0
- package/redscript-docs/docs/zh/stdlib/sort.md +104 -0
- package/redscript-docs/docs/zh/stdlib/spawn.md +142 -0
- package/redscript-docs/docs/zh/stdlib/state.md +134 -0
- package/redscript-docs/docs/zh/stdlib/strings.md +107 -0
- package/redscript-docs/docs/zh/stdlib/tags.md +3451 -0
- package/redscript-docs/docs/zh/stdlib/teams.md +150 -0
- package/redscript-docs/docs/zh/stdlib/timer.md +254 -0
- package/redscript-docs/docs/zh/stdlib/vec.md +158 -0
- package/redscript-docs/docs/zh/stdlib/world.md +289 -0
- package/src/__tests__/formatter-extra.test.ts +139 -0
- package/src/__tests__/global-vars.test.ts +171 -0
- package/src/__tests__/lint/new-rules.test.ts +437 -0
- package/src/__tests__/lsp-rename.test.ts +171 -0
- package/src/__tests__/mc-integration/say-fstring.test.ts +211 -0
- package/src/__tests__/mc-integration/stdlib-coverage-2.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-3.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-4.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-5.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-6.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-7.test.ts +1 -1
- package/src/__tests__/mc-integration/stdlib-coverage-8.test.ts +1 -1
- package/src/__tests__/mc-syntax.test.ts +3 -0
- package/src/__tests__/monomorphize-coverage.test.ts +220 -0
- package/src/__tests__/optimizer-cse.test.ts +250 -0
- package/src/__tests__/parser.test.ts +4 -13
- package/src/__tests__/repl-server-extra.test.ts +6 -6
- package/src/__tests__/repl-server.test.ts +5 -6
- package/src/__tests__/stdlib/queue.test.ts +6 -6
- package/src/lexer/index.ts +2 -1
- package/src/lint/index.ts +713 -5
- package/src/mc-test/client.ts +40 -0
- package/src/mir/lower.ts +111 -2
- package/src/optimizer/interprocedural.ts +40 -2
- package/src/parser/decl-parser.ts +349 -0
- package/src/parser/expr-parser.ts +838 -0
- package/src/parser/index.ts +17 -2558
- package/src/parser/stmt-parser.ts +585 -0
- package/src/parser/type-parser.ts +276 -0
- package/src/parser/utils.ts +173 -0
- package/src/stdlib/queue.mcrs +19 -6
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# Bigint
|
|
2
|
+
|
|
3
|
+
> Auto-generated from `src/stdlib/bigint.mcrs` — do not edit manually.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
- [bigint_base](#bigint-base)
|
|
8
|
+
- [bigint_zero](#bigint-zero)
|
|
9
|
+
- [bigint_copy](#bigint-copy)
|
|
10
|
+
- [bigint_cmp](#bigint-cmp)
|
|
11
|
+
- [bigint_add](#bigint-add)
|
|
12
|
+
- [bigint_sub](#bigint-sub)
|
|
13
|
+
- [bigint_mul_small](#bigint-mul-small)
|
|
14
|
+
- [bigint_div_small](#bigint-div-small)
|
|
15
|
+
- [bigint_mod_small](#bigint-mod-small)
|
|
16
|
+
- [bigint_mul](#bigint-mul)
|
|
17
|
+
- [bigint_sq](#bigint-sq)
|
|
18
|
+
- [bigint_div](#bigint-div)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## `bigint_base` <Badge type="info" text="v1.0.0" />
|
|
23
|
+
|
|
24
|
+
Return the bigint base (10000 = base-10000, each chunk holds 4 decimal digits).
|
|
25
|
+
|
|
26
|
+
```redscript
|
|
27
|
+
fn bigint_base(): int
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Returns:** 10000
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## `bigint_zero` <Badge type="info" text="v1.0.0" />
|
|
35
|
+
|
|
36
|
+
Set all chunks of a bigint array to zero.
|
|
37
|
+
|
|
38
|
+
```redscript
|
|
39
|
+
fn bigint_zero(arr: int[], len: int)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Parameters**
|
|
43
|
+
|
|
44
|
+
| Parameter | Description |
|
|
45
|
+
|-----------|-------------|
|
|
46
|
+
| `arr` | BigInt array (most-significant chunk at index 0) |
|
|
47
|
+
| `len` | Number of chunks |
|
|
48
|
+
|
|
49
|
+
**Returns:** void — arr[0..len-1] set to 0
|
|
50
|
+
|
|
51
|
+
**Example**
|
|
52
|
+
|
|
53
|
+
```redscript
|
|
54
|
+
bigint_zero(result, 4) // zero out a 4-chunk bigint
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## `bigint_copy` <Badge type="info" text="v1.0.0" />
|
|
60
|
+
|
|
61
|
+
Copy a bigint from src into dst.
|
|
62
|
+
|
|
63
|
+
```redscript
|
|
64
|
+
fn bigint_copy(src: int[], dst: int[], len: int)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Parameters**
|
|
68
|
+
|
|
69
|
+
| Parameter | Description |
|
|
70
|
+
|-----------|-------------|
|
|
71
|
+
| `src` | Source bigint array |
|
|
72
|
+
| `dst` | Destination bigint array (must have length >= len) |
|
|
73
|
+
| `len` | Number of chunks to copy |
|
|
74
|
+
|
|
75
|
+
**Returns:** void — dst[0..len-1] = src[0..len-1]
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## `bigint_cmp` <Badge type="info" text="v1.0.0" />
|
|
80
|
+
|
|
81
|
+
Compare two bigints of equal length.
|
|
82
|
+
|
|
83
|
+
```redscript
|
|
84
|
+
fn bigint_cmp(a: int[], b: int[], len: int): int
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Parameters**
|
|
88
|
+
|
|
89
|
+
| Parameter | Description |
|
|
90
|
+
|-----------|-------------|
|
|
91
|
+
| `a` | First bigint (most-significant chunk at index 0) |
|
|
92
|
+
| `b` | Second bigint |
|
|
93
|
+
| `len` | Number of chunks (must be equal for both) |
|
|
94
|
+
|
|
95
|
+
**Returns:** 1 if a > b, -1 if a < b, 0 if equal
|
|
96
|
+
|
|
97
|
+
**Example**
|
|
98
|
+
|
|
99
|
+
```redscript
|
|
100
|
+
let cmp: int = bigint_cmp(a, b, 4)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## `bigint_add` <Badge type="info" text="v1.0.0" />
|
|
106
|
+
|
|
107
|
+
Add two bigints of equal length, writing result into a pre-allocated array.
|
|
108
|
+
|
|
109
|
+
```redscript
|
|
110
|
+
fn bigint_add(a: int[], b: int[], result: int[], len: int): int
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Parameters**
|
|
114
|
+
|
|
115
|
+
| Parameter | Description |
|
|
116
|
+
|-----------|-------------|
|
|
117
|
+
| `a` | First bigint addend |
|
|
118
|
+
| `b` | Second bigint addend |
|
|
119
|
+
| `result` | Output bigint array (must have length >= len, may alias a or b) |
|
|
120
|
+
| `len` | Number of chunks |
|
|
121
|
+
|
|
122
|
+
**Returns:** Carry out: 0 or 1 (overflow if non-zero)
|
|
123
|
+
|
|
124
|
+
**Example**
|
|
125
|
+
|
|
126
|
+
```redscript
|
|
127
|
+
let carry: int = bigint_add(a, b, result, 4)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## `bigint_sub` <Badge type="info" text="v1.0.0" />
|
|
133
|
+
|
|
134
|
+
Subtract bigint b from a, writing result (assumes a >= b, no underflow check).
|
|
135
|
+
|
|
136
|
+
```redscript
|
|
137
|
+
fn bigint_sub(a: int[], b: int[], result: int[], len: int)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Parameters**
|
|
141
|
+
|
|
142
|
+
| Parameter | Description |
|
|
143
|
+
|-----------|-------------|
|
|
144
|
+
| `a` | Minuend bigint |
|
|
145
|
+
| `b` | Subtrahend bigint (must be <= a) |
|
|
146
|
+
| `result` | Output bigint array |
|
|
147
|
+
| `len` | Number of chunks |
|
|
148
|
+
|
|
149
|
+
**Returns:** void — result = a - b
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## `bigint_mul_small` <Badge type="info" text="v1.0.0" />
|
|
154
|
+
|
|
155
|
+
Multiply a bigint by a small integer (1 ≤ n ≤ 9999).
|
|
156
|
+
|
|
157
|
+
```redscript
|
|
158
|
+
fn bigint_mul_small(a: int[], n: int, result: int[], len: int)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Parameters**
|
|
162
|
+
|
|
163
|
+
| Parameter | Description |
|
|
164
|
+
|-----------|-------------|
|
|
165
|
+
| `a` | Bigint multiplicand |
|
|
166
|
+
| `n` | Small integer multiplier (must be in [1, 9999] to avoid overflow) |
|
|
167
|
+
| `result` | Output bigint array (must have length >= len) |
|
|
168
|
+
| `len` | Number of chunks |
|
|
169
|
+
|
|
170
|
+
**Returns:** void — result = a * n; high overflow is silently lost
|
|
171
|
+
|
|
172
|
+
**Example**
|
|
173
|
+
|
|
174
|
+
```redscript
|
|
175
|
+
bigint_mul_small(a, 1000, result, 4) // result = a × 1000
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
## `bigint_div_small` <Badge type="info" text="v1.0.0" />
|
|
181
|
+
|
|
182
|
+
Divide a bigint by a small integer (1 ≤ divisor ≤ 9999), returning quotient and remainder.
|
|
183
|
+
|
|
184
|
+
```redscript
|
|
185
|
+
fn bigint_div_small(a: int[], divisor: int, result: int[], len: int): int
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
**Parameters**
|
|
189
|
+
|
|
190
|
+
| Parameter | Description |
|
|
191
|
+
|-----------|-------------|
|
|
192
|
+
| `a` | Dividend bigint |
|
|
193
|
+
| `divisor` | Small integer divisor (range [1, 9999]) |
|
|
194
|
+
| `result` | Output quotient bigint array |
|
|
195
|
+
| `len` | Number of chunks |
|
|
196
|
+
|
|
197
|
+
**Returns:** Remainder (0..divisor-1)
|
|
198
|
+
|
|
199
|
+
**Example**
|
|
200
|
+
|
|
201
|
+
```redscript
|
|
202
|
+
let rem: int = bigint_div_small(a, 7, result, 4)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## `bigint_mod_small` <Badge type="info" text="v1.0.0" />
|
|
208
|
+
|
|
209
|
+
Compute a bigint modulo a small integer without allocating a quotient array.
|
|
210
|
+
|
|
211
|
+
```redscript
|
|
212
|
+
fn bigint_mod_small(a: int[], divisor: int, len: int): int
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Parameters**
|
|
216
|
+
|
|
217
|
+
| Parameter | Description |
|
|
218
|
+
|-----------|-------------|
|
|
219
|
+
| `a` | Dividend bigint |
|
|
220
|
+
| `divisor` | Small integer divisor (range [1, 9999]) |
|
|
221
|
+
| `len` | Number of chunks |
|
|
222
|
+
|
|
223
|
+
**Returns:** a % divisor, in [0, divisor-1]
|
|
224
|
+
|
|
225
|
+
**Example**
|
|
226
|
+
|
|
227
|
+
```redscript
|
|
228
|
+
let mod: int = bigint_mod_small(a, 10, 4) // last decimal digit of a
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## `bigint_mul` <Badge type="info" text="v1.0.0" />
|
|
234
|
+
|
|
235
|
+
Multiply two bigints using schoolbook O(n²) algorithm.
|
|
236
|
+
|
|
237
|
+
```redscript
|
|
238
|
+
fn bigint_mul(a: int[], b: int[], result: int[], la: int, lb: int)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Parameters**
|
|
242
|
+
|
|
243
|
+
| Parameter | Description |
|
|
244
|
+
|-----------|-------------|
|
|
245
|
+
| `a` | First bigint (la chunks) |
|
|
246
|
+
| `b` | Second bigint (lb chunks) |
|
|
247
|
+
| `result` | Output bigint array (must have la+lb chunks, pre-zeroed) |
|
|
248
|
+
| `la` | Number of chunks in a |
|
|
249
|
+
| `lb` | Number of chunks in b |
|
|
250
|
+
|
|
251
|
+
**Returns:** void — result = a * b; result must not alias a or b
|
|
252
|
+
|
|
253
|
+
**Example**
|
|
254
|
+
|
|
255
|
+
```redscript
|
|
256
|
+
let result: int[] = [0, 0, 0, 0, 0, 0, 0]
|
|
257
|
+
bigint_mul(a, b, result, 4, 3)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## `bigint_sq` <Badge type="info" text="v1.0.0" />
|
|
263
|
+
|
|
264
|
+
Square a bigint (optimized: computes upper triangle only).
|
|
265
|
+
|
|
266
|
+
```redscript
|
|
267
|
+
fn bigint_sq(a: int[], result: int[], len: int)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
**Parameters**
|
|
271
|
+
|
|
272
|
+
| Parameter | Description |
|
|
273
|
+
|-----------|-------------|
|
|
274
|
+
| `a` | Bigint to square (len chunks) |
|
|
275
|
+
| `result` | Output bigint array (must have len*2 chunks, pre-zeroed) |
|
|
276
|
+
| `len` | Number of chunks in a |
|
|
277
|
+
|
|
278
|
+
**Returns:** void — result = a * a
|
|
279
|
+
|
|
280
|
+
**Example**
|
|
281
|
+
|
|
282
|
+
```redscript
|
|
283
|
+
let sq: int[] = [0, 0, 0, 0, 0, 0, 0, 0]
|
|
284
|
+
bigint_sq(a, sq, 4) // sq = a²
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## `bigint_div` <Badge type="info" text="v1.0.0" />
|
|
290
|
+
|
|
291
|
+
Full arbitrary-precision integer division: a / b → quotient and remainder.
|
|
292
|
+
|
|
293
|
+
```redscript
|
|
294
|
+
fn bigint_div(a: int[], b: int[], quotient: int[], remainder: int[], la: int, lb: int): void
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Parameters**
|
|
298
|
+
|
|
299
|
+
| Parameter | Description |
|
|
300
|
+
|-----------|-------------|
|
|
301
|
+
| `a` | Dividend bigint (la chunks) |
|
|
302
|
+
| `b` | Divisor bigint (lb chunks) |
|
|
303
|
+
| `quotient` | Output quotient array (la chunks, pre-zeroed) |
|
|
304
|
+
| `remainder` | Output remainder array (lb chunks, pre-zeroed) |
|
|
305
|
+
| `la` | Number of chunks in a (must be >= lb) |
|
|
306
|
+
| `lb` | Number of chunks in b |
|
|
307
|
+
|
|
308
|
+
**Returns:** void — quotient = a/b, remainder = a%b; a and b must not alias outputs
|
|
309
|
+
|
|
310
|
+
**Example**
|
|
311
|
+
|
|
312
|
+
```redscript
|
|
313
|
+
bigint_div(a, b, quotient, remainder, 4, 2)
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
---
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# Bits
|
|
2
|
+
|
|
3
|
+
> Auto-generated from `src/stdlib/bits.mcrs` — do not edit manually.
|
|
4
|
+
|
|
5
|
+
## API
|
|
6
|
+
|
|
7
|
+
- [bit_get](#bit-get)
|
|
8
|
+
- [bit_set](#bit-set)
|
|
9
|
+
- [bit_clear](#bit-clear)
|
|
10
|
+
- [bit_toggle](#bit-toggle)
|
|
11
|
+
- [bit_shl](#bit-shl)
|
|
12
|
+
- [bit_shr](#bit-shr)
|
|
13
|
+
- [bit_and](#bit-and)
|
|
14
|
+
- [bit_or](#bit-or)
|
|
15
|
+
- [bit_xor](#bit-xor)
|
|
16
|
+
- [bit_not](#bit-not)
|
|
17
|
+
- [popcount](#popcount)
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## `bit_get` <Badge type="info" text="v1.0.0" />
|
|
22
|
+
|
|
23
|
+
Test whether bit n of x is set.
|
|
24
|
+
|
|
25
|
+
```redscript
|
|
26
|
+
fn bit_get(x: int, n: int): int
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
**Parameters**
|
|
30
|
+
|
|
31
|
+
| Parameter | Description |
|
|
32
|
+
|-----------|-------------|
|
|
33
|
+
| `x` | Integer value to test |
|
|
34
|
+
| `n` | Bit index (0 = least significant), range [0, 30] |
|
|
35
|
+
|
|
36
|
+
**Returns:** 1 if bit n is set, 0 otherwise
|
|
37
|
+
|
|
38
|
+
**Example**
|
|
39
|
+
|
|
40
|
+
```redscript
|
|
41
|
+
let b: int = bit_get(0b1010, 1) // result: 1 (bit 1 of 10 is set)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## `bit_set` <Badge type="info" text="v1.0.0" />
|
|
47
|
+
|
|
48
|
+
Set bit n of x to 1 (idempotent if already set).
|
|
49
|
+
|
|
50
|
+
```redscript
|
|
51
|
+
fn bit_set(x: int, n: int): int
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**Parameters**
|
|
55
|
+
|
|
56
|
+
| Parameter | Description |
|
|
57
|
+
|-----------|-------------|
|
|
58
|
+
| `x` | Integer value to modify |
|
|
59
|
+
| `n` | Bit index to set, range [0, 30] |
|
|
60
|
+
|
|
61
|
+
**Returns:** x with bit n set to 1
|
|
62
|
+
|
|
63
|
+
**Example**
|
|
64
|
+
|
|
65
|
+
```redscript
|
|
66
|
+
let v: int = bit_set(0b0100, 0) // result: 0b0101 = 5
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## `bit_clear` <Badge type="info" text="v1.0.0" />
|
|
72
|
+
|
|
73
|
+
Clear bit n of x to 0 (idempotent if already clear).
|
|
74
|
+
|
|
75
|
+
```redscript
|
|
76
|
+
fn bit_clear(x: int, n: int): int
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Parameters**
|
|
80
|
+
|
|
81
|
+
| Parameter | Description |
|
|
82
|
+
|-----------|-------------|
|
|
83
|
+
| `x` | Integer value to modify |
|
|
84
|
+
| `n` | Bit index to clear, range [0, 30] |
|
|
85
|
+
|
|
86
|
+
**Returns:** x with bit n set to 0
|
|
87
|
+
|
|
88
|
+
**Example**
|
|
89
|
+
|
|
90
|
+
```redscript
|
|
91
|
+
let v: int = bit_clear(0b0111, 1) // result: 0b0101 = 5
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## `bit_toggle` <Badge type="info" text="v1.0.0" />
|
|
97
|
+
|
|
98
|
+
Toggle bit n of x (flip 0→1 or 1→0).
|
|
99
|
+
|
|
100
|
+
```redscript
|
|
101
|
+
fn bit_toggle(x: int, n: int): int
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**Parameters**
|
|
105
|
+
|
|
106
|
+
| Parameter | Description |
|
|
107
|
+
|-----------|-------------|
|
|
108
|
+
| `x` | Integer value to modify |
|
|
109
|
+
| `n` | Bit index to toggle, range [0, 30] |
|
|
110
|
+
|
|
111
|
+
**Returns:** x with bit n flipped
|
|
112
|
+
|
|
113
|
+
**Example**
|
|
114
|
+
|
|
115
|
+
```redscript
|
|
116
|
+
let v: int = bit_toggle(0b0101, 1) // result: 0b0111 = 7
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## `bit_shl` <Badge type="info" text="v1.0.0" />
|
|
122
|
+
|
|
123
|
+
Left-shift x by n bits (equivalent to x * 2^n).
|
|
124
|
+
|
|
125
|
+
```redscript
|
|
126
|
+
fn bit_shl(x: int, n: int): int
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Parameters**
|
|
130
|
+
|
|
131
|
+
| Parameter | Description |
|
|
132
|
+
|-----------|-------------|
|
|
133
|
+
| `x` | Integer to shift |
|
|
134
|
+
| `n` | Number of bit positions to shift left, range [0, 30] |
|
|
135
|
+
|
|
136
|
+
**Returns:** x << n
|
|
137
|
+
|
|
138
|
+
**Example**
|
|
139
|
+
|
|
140
|
+
```redscript
|
|
141
|
+
let v: int = bit_shl(1, 4) // result: 16 (1 << 4)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## `bit_shr` <Badge type="info" text="v1.0.0" />
|
|
147
|
+
|
|
148
|
+
Logical right-shift x by n bits (equivalent to x / 2^n, truncating toward zero).
|
|
149
|
+
|
|
150
|
+
```redscript
|
|
151
|
+
fn bit_shr(x: int, n: int): int
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Parameters**
|
|
155
|
+
|
|
156
|
+
| Parameter | Description |
|
|
157
|
+
|-----------|-------------|
|
|
158
|
+
| `x` | Integer to shift |
|
|
159
|
+
| `n` | Number of bit positions to shift right, range [0, 30] |
|
|
160
|
+
|
|
161
|
+
**Returns:** x >> n (logical, not arithmetic for positive values)
|
|
162
|
+
|
|
163
|
+
**Example**
|
|
164
|
+
|
|
165
|
+
```redscript
|
|
166
|
+
let v: int = bit_shr(256, 3) // result: 32 (256 >> 3)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## `bit_and` <Badge type="info" text="v1.0.0" />
|
|
172
|
+
|
|
173
|
+
Bitwise AND of two integers (all 31 non-sign bits).
|
|
174
|
+
|
|
175
|
+
```redscript
|
|
176
|
+
fn bit_and(a: int, b: int): int
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Parameters**
|
|
180
|
+
|
|
181
|
+
| Parameter | Description |
|
|
182
|
+
|-----------|-------------|
|
|
183
|
+
| `a` | First operand |
|
|
184
|
+
| `b` | Second operand |
|
|
185
|
+
|
|
186
|
+
**Returns:** a & b (bits set in both a and b)
|
|
187
|
+
|
|
188
|
+
**Example**
|
|
189
|
+
|
|
190
|
+
```redscript
|
|
191
|
+
let v: int = bit_and(0b1100, 0b1010) // result: 0b1000 = 8
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## `bit_or` <Badge type="info" text="v1.0.0" />
|
|
197
|
+
|
|
198
|
+
Bitwise OR of two integers (all 31 non-sign bits).
|
|
199
|
+
|
|
200
|
+
```redscript
|
|
201
|
+
fn bit_or(a: int, b: int): int
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Parameters**
|
|
205
|
+
|
|
206
|
+
| Parameter | Description |
|
|
207
|
+
|-----------|-------------|
|
|
208
|
+
| `a` | First operand |
|
|
209
|
+
| `b` | Second operand |
|
|
210
|
+
|
|
211
|
+
**Returns:** a | b (bits set in either a or b)
|
|
212
|
+
|
|
213
|
+
**Example**
|
|
214
|
+
|
|
215
|
+
```redscript
|
|
216
|
+
let v: int = bit_or(0b1100, 0b1010) // result: 0b1110 = 14
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## `bit_xor` <Badge type="info" text="v1.0.0" />
|
|
222
|
+
|
|
223
|
+
Bitwise XOR of two integers (all 31 non-sign bits).
|
|
224
|
+
|
|
225
|
+
```redscript
|
|
226
|
+
fn bit_xor(a: int, b: int): int
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Parameters**
|
|
230
|
+
|
|
231
|
+
| Parameter | Description |
|
|
232
|
+
|-----------|-------------|
|
|
233
|
+
| `a` | First operand |
|
|
234
|
+
| `b` | Second operand |
|
|
235
|
+
|
|
236
|
+
**Returns:** a ^ b (bits set in exactly one of a or b)
|
|
237
|
+
|
|
238
|
+
**Example**
|
|
239
|
+
|
|
240
|
+
```redscript
|
|
241
|
+
let v: int = bit_xor(0b1100, 0b1010) // result: 0b0110 = 6
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## `bit_not` <Badge type="info" text="v1.0.0" />
|
|
247
|
+
|
|
248
|
+
Bitwise NOT — inverts all 31 non-sign bits of x.
|
|
249
|
+
|
|
250
|
+
```redscript
|
|
251
|
+
fn bit_not(x: int): int
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
**Parameters**
|
|
255
|
+
|
|
256
|
+
| Parameter | Description |
|
|
257
|
+
|-----------|-------------|
|
|
258
|
+
| `x` | Integer to invert |
|
|
259
|
+
|
|
260
|
+
**Returns:** ~x (all 31 lower bits flipped; sign bit excluded)
|
|
261
|
+
|
|
262
|
+
**Example**
|
|
263
|
+
|
|
264
|
+
```redscript
|
|
265
|
+
let v: int = bit_not(0) // result: 2147483647 (all 31 bits set)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## `popcount` <Badge type="info" text="v1.0.0" />
|
|
271
|
+
|
|
272
|
+
Count the number of set bits in x (population count / Hamming weight).
|
|
273
|
+
|
|
274
|
+
```redscript
|
|
275
|
+
fn popcount(x: int): int
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
**Parameters**
|
|
279
|
+
|
|
280
|
+
| Parameter | Description |
|
|
281
|
+
|-----------|-------------|
|
|
282
|
+
| `x` | Integer value (uses 31 lower bits; sign bit excluded) |
|
|
283
|
+
|
|
284
|
+
**Returns:** Number of bits set to 1, in [0, 31]
|
|
285
|
+
|
|
286
|
+
**Example**
|
|
287
|
+
|
|
288
|
+
```redscript
|
|
289
|
+
let n: int = popcount(255) // result: 8 (0xFF has 8 bits set)
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|