Proposal: Vec.* vector math + finish Math transcendentals & Ease.elastic #25

Closed
opened 2026-08-29 23:39:27 +02:00 by orkun · 2 comments
Owner

Follow-up to #2 — the remaining stdlib numerics.

Vec.* (depends on #1)

Vec.make/add/sub/scale/dot/length/normalize/rotate/angle/from_angle/lerp/distance. These pair with the vec2 type proposed in #1 (the type system), so they are blocked on #1 — without a 2D vector type there is nothing to return.

Finish Math / Ease

Math.pow, Math.exp, Math.log and Ease.elastic were deferred in #2 because they need a fixed-point exp/2^x (via a range-reduced polynomial or table). Low priority for a game language, but they round out the surface.

Blocked on: #1 (vec2 type) for Vec.*; a fixed-point exp/log for the rest.

Follow-up to #2 — the remaining stdlib numerics. ## Vec.* (depends on #1) `Vec.make/add/sub/scale/dot/length/normalize/rotate/angle/from_angle/lerp/distance`. These pair with the `vec2` type proposed in #1 (the type system), so they are **blocked on #1** — without a 2D vector type there is nothing to return. ## Finish Math / Ease `Math.pow`, `Math.exp`, `Math.log` and `Ease.elastic` were deferred in #2 because they need a fixed-point `exp`/`2^x` (via a range-reduced polynomial or table). Low priority for a game language, but they round out the surface. **Blocked on:** #1 (vec2 type) for `Vec.*`; a fixed-point `exp`/`log` for the rest.
orkun added the
proposal
priority:low
area:stdlib
labels 2026-08-29 23:39:27 +02:00
Author
Owner

The Math / Ease half of this issue is implemented and pushed to main in 6e6467b.

Shipped (deterministic Q16.16, pure integer IR — bit-identical everywhere):

  • Math.exp, Math.log (natural log), Math.pow — backed by two new prelude functions: @fn_fx_exp2 (range-reduced 5th-order Taylor 2^f, then a clamped shift by the integer part) and @fn_fx_log2 (llvm.ctlz for the exponent + an atanh series on (m-1)/(m+1) for the mantissa). exp = 2^(x·log₂e), log = log₂(x)·ln2, pow = 2^(b·log₂a).
  • Ease.elastic — ease-out elastic, 2^(-10t)·sin((10t-0.75)·2π/3)+1.

Domain note: results must fit the Q16.16 range (|x| < 32768); larger magnitudes saturate (e.g. pow(2, 16) → 0). Documented on each page.

Tests (selfhost/tests/transcend.ludic) + docs for all four; reseeded, C-free bootstrap fixpoint holds, all suites green.

Left open: the Vec.* half stays blocked on #1 — without a vec2 type there is nothing for Vec.make/add/dot/normalize/… to return. This issue remains open to track that half.

The **Math / Ease** half of this issue is implemented and pushed to `main` in 6e6467b. **Shipped (deterministic Q16.16, pure integer IR — bit-identical everywhere):** - `Math.exp`, `Math.log` (natural log), `Math.pow` — backed by two new prelude functions: `@fn_fx_exp2` (range-reduced 5th-order Taylor `2^f`, then a clamped shift by the integer part) and `@fn_fx_log2` (`llvm.ctlz` for the exponent + an atanh series on `(m-1)/(m+1)` for the mantissa). `exp = 2^(x·log₂e)`, `log = log₂(x)·ln2`, `pow = 2^(b·log₂a)`. - `Ease.elastic` — ease-out elastic, `2^(-10t)·sin((10t-0.75)·2π/3)+1`. Domain note: results must fit the Q16.16 range (`|x| < 32768`); larger magnitudes saturate (e.g. `pow(2, 16)` → 0). Documented on each page. Tests (`selfhost/tests/transcend.ludic`) + docs for all four; reseeded, C-free bootstrap fixpoint holds, all suites green. **Left open:** the `Vec.*` half stays blocked on #1 — without a `vec2` type there is nothing for `Vec.make/add/dot/normalize/…` to return. This issue remains open to track that half.
Author
Owner

The Vec. half* is now implemented and pushed to main (121053e), so both halves of this issue are complete — closing.

Vector math — shipped as Vector.* (de-abbreviated from the proposed Vec). Rather than block on the full #1 type system, a self-contained value type unblocks it: a Vector is two Q16.16 fixed components packed into one i64, so it is copied by value and never allocates (reuses the long/i64 support from #17; llty maps Vector → i64). Fifteen deterministic fixed-point ops reusing the existing fx_mul/fx_div/fx_lerp and @fn_fx_* prelude:
make / zero / x / y, add / sub / scale / dot, length / distance / normalize / lerp, rotate / angle / from_angle.
New selfhost/emit_vector.ludic, the Vector primitive type, grammars/LSP tokens, 16 doc pages, and a registered test (verified on a 3-4-5 triangle, a 90° rotation, atan2, lerp, etc.).

Math / Ease half was completed earlier in 6e6467b: Math.exp, Math.log, Math.pow (via new @fn_fx_exp2/@fn_fx_log2 prelude) and Ease.elastic.

Separately, the abbreviated names across the language were expanded to full words in the surrounding commits — Vec→Vector, and while there: Mem→Memory, Sys→System, Net→Network, Collide→Collision, the fn keyword→function, str→string, ptr/ptrs→pointer/pointers, and the flr/fx builtins→floor/fixed. int/bool/Math keep their conventional short spelling.

All suites green (45 regression, 25 self-host, 29 tool); the C-free bootstrap fixpoint holds and the docs site regenerates cleanly.

The **Vec.* half** is now implemented and pushed to `main` (121053e), so both halves of this issue are complete — closing. **Vector math — shipped as `Vector.*`** (de-abbreviated from the proposed `Vec`). Rather than block on the full #1 type system, a self-contained value type unblocks it: a `Vector` is two Q16.16 `fixed` components packed into one `i64`, so it is copied by value and never allocates (reuses the `long`/i64 support from #17; `llty` maps `Vector` → i64). Fifteen deterministic fixed-point ops reusing the existing `fx_mul`/`fx_div`/`fx_lerp` and `@fn_fx_*` prelude: `make` / `zero` / `x` / `y`, `add` / `sub` / `scale` / `dot`, `length` / `distance` / `normalize` / `lerp`, `rotate` / `angle` / `from_angle`. New `selfhost/emit_vector.ludic`, the `Vector` primitive type, grammars/LSP tokens, 16 doc pages, and a registered test (verified on a 3-4-5 triangle, a 90° rotation, `atan2`, lerp, etc.). **Math / Ease half** was completed earlier in 6e6467b: `Math.exp`, `Math.log`, `Math.pow` (via new `@fn_fx_exp2`/`@fn_fx_log2` prelude) and `Ease.elastic`. Separately, the abbreviated names across the language were expanded to full words in the surrounding commits — `Vec`→`Vector`, and while there: `Mem`→`Memory`, `Sys`→`System`, `Net`→`Network`, `Collide`→`Collision`, the `fn` keyword→`function`, `str`→`string`, `ptr`/`ptrs`→`pointer`/`pointers`, and the `flr`/`fx` builtins→`floor`/`fixed`. `int`/`bool`/`Math` keep their conventional short spelling. All suites green (45 regression, 25 self-host, 29 tool); the C-free bootstrap fixpoint holds and the docs site regenerates cleanly.
orkun closed this issue 2026-08-30 01:10:17 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: workshopsoft/ludic#25
No description provided.