math refactor #469

Merged
navicore merged 1 commit from fmath into main 2026-05-10 15:39:28 +00:00
Owner

● Full just ci green: fmt, clippy, unit tests, compiler/LSP/examples build, integration tests (41 passed including
all 23 new builtins), seq lint, binary contents.

Summary of changes

Runtime (crates/runtime/src/float_ops.rs)

  • Added 17 unary FFI shims via f_unary! macro: sqrt, cbrt, exp, ln, log10, log2, sin, cos, tan, asin, acos,
    atan, floor, ceil, round (round_ties_even/banker's), trunc.
  • Added 2 binary FFI shims: f.pow ( base exp -- result ), f.atan2 ( y x -- result ).
  • Added 3 zero-arg constants via f_const! macro: f.pi, f.e, f.tau from std::f64::consts::*.

Compiler signatures (crates/compiler/src/builtins/float.rs) — 23 builtin! lines, 23 doc strings (f.round calls
out banker's; f.atan2 and f.pow call out arg order).

Codegen wiring — both crates/compiler/src/codegen/runtime/float.rs (DECLS + SYMBOLS) and
crates/compiler/src/ast/program.rs (validate_word_calls known-builtins list).

Linker (crates/compiler/src/lib.rs) — added -lm so libm symbols (sin, cos, exp, log, pow, atan, …) referenced by
the runtime archive resolve. Comment explains why it's needed (clang only auto-links libm for math in the IR,
not via the runtime).

Stdlib cleanup (crates/compiler/stdlib/imath.seq)

  • Deleted : mod ( Int Int -- Int Bool ) i.modulo ; — the design's "noise" wrapper.
  • Updated gcd to call i.modulo directly with # seq:allow(unchecked-modulo) documenting the base-case screen.
  • Updated header doc block.

Call-site updates

  • examples/paradigms/functional/lists.seq — 2 mod drop → 2 i.modulo drop with seq:allow per word.
  • examples/language/README.md — fixed pre-existing wrong i.mod references to i.modulo drop (per same-commit
    choice).
  • tests/integration/src/test-std-imath.seq — removed test-mod (the wrapper is gone; i.modulo is covered in
    test-division.seq).

Docs (docs/STDLIB_REFERENCE.md)

  • New top-level "Float Math" section with five subsections (roots/powers, exp/log, trig, rounding, constants).
  • TOC entry added.
  • std:imath table: dropped mod, added pointer to i.modulo.
  • std:fmath table: added pointer to the new builtin section.

Migration doc (docs/MIGRATION_7_0.md) — created with two rules: (1) mod → i.modulo; (2) float math builtins are
additive, no migration required, with semantics notes (banker's rounding, f.atan2 ( y x -- ), f.pow ( base exp
-- )).

Integration tests (tests/integration/src/test-std-fmath.seq) — 22 new test words covering every checkpoint in
the design plus per-group smoke tests, all using exact-result inputs to avoid float-equality fragility.

Diff lives unstaged in your worktree (per your git rule).

● Full just ci green: fmt, clippy, unit tests, compiler/LSP/examples build, integration tests (41 passed including all 23 new builtins), seq lint, binary contents. Summary of changes Runtime (crates/runtime/src/float_ops.rs) - Added 17 unary FFI shims via f_unary! macro: sqrt, cbrt, exp, ln, log10, log2, sin, cos, tan, asin, acos, atan, floor, ceil, round (round_ties_even/banker's), trunc. - Added 2 binary FFI shims: f.pow ( base exp -- result ), f.atan2 ( y x -- result ). - Added 3 zero-arg constants via f_const! macro: f.pi, f.e, f.tau from std::f64::consts::*. Compiler signatures (crates/compiler/src/builtins/float.rs) — 23 builtin! lines, 23 doc strings (f.round calls out banker's; f.atan2 and f.pow call out arg order). Codegen wiring — both crates/compiler/src/codegen/runtime/float.rs (DECLS + SYMBOLS) and crates/compiler/src/ast/program.rs (validate_word_calls known-builtins list). Linker (crates/compiler/src/lib.rs) — added -lm so libm symbols (sin, cos, exp, log, pow, atan, …) referenced by the runtime archive resolve. Comment explains why it's needed (clang only auto-links libm for math in the IR, not via the runtime). Stdlib cleanup (crates/compiler/stdlib/imath.seq) - Deleted : mod ( Int Int -- Int Bool ) i.modulo ; — the design's "noise" wrapper. - Updated gcd to call i.modulo directly with # seq:allow(unchecked-modulo) documenting the base-case screen. - Updated header doc block. Call-site updates - examples/paradigms/functional/lists.seq — 2 mod drop → 2 i.modulo drop with seq:allow per word. - examples/language/README.md — fixed pre-existing wrong i.mod references to i.modulo drop (per same-commit choice). - tests/integration/src/test-std-imath.seq — removed test-mod (the wrapper is gone; i.modulo is covered in test-division.seq). Docs (docs/STDLIB_REFERENCE.md) - New top-level "Float Math" section with five subsections (roots/powers, exp/log, trig, rounding, constants). - TOC entry added. - std:imath table: dropped mod, added pointer to i.modulo. - std:fmath table: added pointer to the new builtin section. Migration doc (docs/MIGRATION_7_0.md) — created with two rules: (1) mod → i.modulo; (2) float math builtins are additive, no migration required, with semantics notes (banker's rounding, f.atan2 ( y x -- ), f.pow ( base exp -- )). Integration tests (tests/integration/src/test-std-fmath.seq) — 22 new test words covering every checkpoint in the design plus per-group smoke tests, all using exact-result inputs to avoid float-equality fragility. Diff lives unstaged in your worktree (per your git rule).
math refactor
All checks were successful
CI - Linux / CI - Linux x86_64 (pull_request) Successful in 8m57s
f5f9a82433
● Full just ci green: fmt, clippy, unit tests, compiler/LSP/examples build, integration tests (41 passed including
   all 23 new builtins), seq lint, binary contents.

  Summary of changes

  Runtime (crates/runtime/src/float_ops.rs)
  - Added 17 unary FFI shims via f_unary! macro: sqrt, cbrt, exp, ln, log10, log2, sin, cos, tan, asin, acos,
  atan, floor, ceil, round (round_ties_even/banker's), trunc.
  - Added 2 binary FFI shims: f.pow ( base exp -- result ), f.atan2 ( y x -- result ).
  - Added 3 zero-arg constants via f_const! macro: f.pi, f.e, f.tau from std::f64::consts::*.

  Compiler signatures (crates/compiler/src/builtins/float.rs) — 23 builtin! lines, 23 doc strings (f.round calls
  out banker's; f.atan2 and f.pow call out arg order).

  Codegen wiring — both crates/compiler/src/codegen/runtime/float.rs (DECLS + SYMBOLS) and
  crates/compiler/src/ast/program.rs (validate_word_calls known-builtins list).

  Linker (crates/compiler/src/lib.rs) — added -lm so libm symbols (sin, cos, exp, log, pow, atan, …) referenced by
   the runtime archive resolve. Comment explains why it's needed (clang only auto-links libm for math in the IR,
  not via the runtime).

  Stdlib cleanup (crates/compiler/stdlib/imath.seq)
  - Deleted : mod ( Int Int -- Int Bool ) i.modulo ; — the design's "noise" wrapper.
  - Updated gcd to call i.modulo directly with # seq:allow(unchecked-modulo) documenting the base-case screen.
  - Updated header doc block.

  Call-site updates
  - examples/paradigms/functional/lists.seq — 2 mod drop → 2 i.modulo drop with seq:allow per word.
  - examples/language/README.md — fixed pre-existing wrong i.mod references to i.modulo drop (per same-commit
  choice).
  - tests/integration/src/test-std-imath.seq — removed test-mod (the wrapper is gone; i.modulo is covered in
  test-division.seq).

  Docs (docs/STDLIB_REFERENCE.md)
  - New top-level "Float Math" section with five subsections (roots/powers, exp/log, trig, rounding, constants).
  - TOC entry added.
  - std:imath table: dropped mod, added pointer to i.modulo.
  - std:fmath table: added pointer to the new builtin section.

  Migration doc (docs/MIGRATION_7_0.md) — created with two rules: (1) mod → i.modulo; (2) float math builtins are
  additive, no migration required, with semantics notes (banker's rounding, f.atan2 ( y x -- ), f.pow ( base exp
  -- )).

  Integration tests (tests/integration/src/test-std-fmath.seq) — 22 new test words covering every checkpoint in
  the design plus per-group smoke tests, all using exact-result inputs to avoid float-equality fragility.

  Diff lives unstaged in your worktree (per your git rule).
navicore deleted branch fmath 2026-05-10 15:39:28 +00:00
Sign in to join this conversation.
No description provided.