feat(types): Huge + Angle + Percent polish numeric types (#55)
Types phase 5 (polish). A splice-on-demand numeric runtime (runtime/native/numeric.ludic, built on the inline Math.* trig) behind three namespaces: - Huge.* — idle big numbers (normalized mantissa x 10^exponent): from/add/ sub/mul/neg/cmp/sign/mantissa/exp/str (scientific 1.23e45). Display-scale, not lockstep-exact (BigInt/Decimal for exactness). - Angle.* — auto-wrapping radians: from_degrees/to_degrees/wrap/sin/cos/add/ diff (shortest signed rotation)/lerp (shortest arc). - Percent.* — clamped [0,1]: clamp/of/lerp/apply. Remaining phase-5 items are already covered (duration=Duration.*, rune=Unicode.*, i64=long) or need a type-checking pass (handle, typed name, other sized ints) — tracked for later. Wired: parser splice trigger (g_uses_numeric), emit_call dispatch, reseeded seed, a self-asserting example (examples/library/numeric.ludic + feat_case), per-symbol docs + inventory. All suites green incl. golden renders byte- identical and the bootstrap fixpoint. NOTE: fixed `const`s lower to raw-int-typed values (emit_call N_CONST), which breaks fixed comparisons — the runtime uses inline fixed literals instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
539f258d92
commit
5dc8394f22
33 changed files with 23162 additions and 21092 deletions
7
docs/language/percent/_section.md
Normal file
7
docs/language/percent/_section.md
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
id: percent
|
||||
title: Percent
|
||||
order: 16
|
||||
---
|
||||
|
||||
A value clamped to <code>[0, 1]</code> — health fractions, volumes, and the <code>t</code> of an interpolation, without stray values slipping below 0 or above 1. <code>Percent.clamp</code> pins any <code>fixed</code> into range; <code>Percent.of</code> forms a clamped ratio <code>num / den</code>; <code>Percent.lerp</code> interpolates <code>a..b</code> by a clamped <code>t</code>; and <code>Percent.apply</code> scales a value by a clamped fraction. Every operation is deterministic fixed-point. Arguments are positional. Spliced in only when a program mentions <code>Percent.*</code>.
|
||||
22
docs/language/percent/percent-apply.md
Normal file
22
docs/language/percent/percent-apply.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: percent-apply
|
||||
name: Percent.apply
|
||||
category: percent
|
||||
kind: namespace-method
|
||||
tokens: Percent.apply
|
||||
sig: Percent.apply(value, p) -> fixed
|
||||
tip: Scale a value by a clamped percent.
|
||||
order: 3
|
||||
ns: Percent
|
||||
member: apply
|
||||
---
|
||||
|
||||
Scales <code>value</code> by a clamped fraction <code>p</code> — for example, applying a damage-reduction percentage.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let dealt = Percent.apply(damage, 0.75)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/percent/percent-clamp.md
Normal file
22
docs/language/percent/percent-clamp.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: percent-clamp
|
||||
name: Percent.clamp
|
||||
category: percent
|
||||
kind: namespace-method
|
||||
tokens: Percent.clamp
|
||||
sig: Percent.clamp(v) -> fixed
|
||||
tip: Clamp any fixed into [0, 1].
|
||||
order: 0
|
||||
ns: Percent
|
||||
member: clamp
|
||||
---
|
||||
|
||||
Pins any <code>fixed</code> into the range [0, 1] — a health fraction or volume that can never slip out of bounds.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let hp = Percent.clamp(health)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/percent/percent-lerp.md
Normal file
22
docs/language/percent/percent-lerp.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: percent-lerp
|
||||
name: Percent.lerp
|
||||
category: percent
|
||||
kind: namespace-method
|
||||
tokens: Percent.lerp
|
||||
sig: Percent.lerp(a, b, t) -> fixed
|
||||
tip: Interpolate a..b by a clamped t.
|
||||
order: 2
|
||||
ns: Percent
|
||||
member: lerp
|
||||
---
|
||||
|
||||
Interpolates from <code>a</code> to <code>b</code> by <code>t</code>, clamping <code>t</code> to [0, 1] first so the result never overshoots the endpoints.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let x = Percent.lerp(startX, endX, progress)
|
||||
}
|
||||
}
|
||||
```
|
||||
22
docs/language/percent/percent-of.md
Normal file
22
docs/language/percent/percent-of.md
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
id: percent-of
|
||||
name: Percent.of
|
||||
category: percent
|
||||
kind: namespace-method
|
||||
tokens: Percent.of
|
||||
sig: Percent.of(num, den) -> fixed
|
||||
tip: Clamped ratio num / den.
|
||||
order: 1
|
||||
ns: Percent
|
||||
member: of
|
||||
---
|
||||
|
||||
Forms the ratio <code>num / den</code> clamped to [0, 1] (0 when <code>den</code> is 0) — a filled-fraction from a part and a whole.
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
handler Step phase Update {
|
||||
let filled = Percent.of(current, maximum)
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue