Skip to content

prelude: add Math.fmod - #1711

Merged
mbouaziz merged 1 commit into
mainfrom
feat/math-fmod
Nov 19, 2026
Merged

mbouaziz merged 1 commit into
mainfrom
feat/math-fmod

Conversation

@mbouaziz

Copy link
Copy Markdown
Contributor

Summary

Adds Math.fmod(val: Float, divisor: Float): Float to the stdlib Math module (C fmod semantics: the result has the sign of the dividend), alongside sin/cos/pow/etc.

Motivation

The stdlib had no floating-point remainder operation; fmod is needed for e.g. wrapping angles/phases. It is added at the stdlib level (like the other math functions) rather than as a language operator, so no compiler changes were required.

Implementation notes

  • skiplang/prelude/src/stdlib/other/Math.sk: @cpp_extern("fmod") native fun fmod(...). Note there is no llvm.fmod.f64 intrinsic (fmod is LLVM's frem opcode, not an intrinsic), so the libm symbol is bound directly: natively it resolves through libm, and on wasm llc -mtriple=wasm32 lowers the call to an fmod import.
  • skiplang/prelude/ts/wasm/src/sk_runtime.ts: provides the wasm fmod import as (v, d) => v % d (JS % is the truncated remainder, matching C fmod), plus the ToWasm interface entry.
  • skiplang/prelude/Skargo.toml: std bumped 0.6.0 -> 0.7.0 (minor: new prelude API).
  • skiplang/prelude/tests/Math.sk: new sktest suite covering signs, exact multiples, |dividend| < |divisor|, fractional divisors, and special values (+/-inf, NaN, zero divisor).

Validation

Changes touch skiplang/ (prelude + wasm runtime):

  • Full prelude suite (cd skiplang/prelude && SKTEST_JOBS=8 ../../bin/run-sktest.sh): 138/138 pass, including the two new MathTest tests.
  • Native smoke test via skc: fmod(5.5,2.0)=1.5, fmod(-7.0,2.0)=-1.0, fmod(5.0,1.5)=0.5, fmod(7.0,2.0)=1.0.
  • Wasm lowering verified with llc -mtriple=wasm32-unknown-unknown + wasm-ld --allow-undefined: the call becomes an fmod import, which the JS runtime now provides.
  • skfmt and prettier --check clean on the changed files.

AI assistance: implemented with Mistral Vibe; the commit carries a Co-Authored-By trailer.

Adds Math.fmod(val, divisor): Float to the stdlib Math module, bound to
the libm fmod symbol via @cpp_extern("fmod"). There is no llvm.fmod.f64
intrinsic (fmod is LLVM's frem opcode, not an intrinsic), so the libm
symbol is bound directly: natively it resolves through libm, and on wasm
llc lowers the call to an fmod import, provided by the JS runtime as
(v, d) => v % d (JS % is the truncated remainder, matching C fmod).

std bumped to 0.7.0 (minor: new prelude API).

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@mbouaziz
mbouaziz enabled auto-merge November 19, 2026 01:15
@mbouaziz
mbouaziz merged commit dd75571 into main Nov 19, 2026
23 of 24 checks passed
@mbouaziz
mbouaziz deleted the feat/math-fmod branch November 19, 2026 01:28
mbouaziz added a commit that referenced this pull request Nov 19, 2026
Dependabot bumps in examples/cache_invalidation/edge_service and
examples/blogger/reactive_service raised @types/node/typescript/eslint
ranges without a matching root lock update, so `npm ci` at the repo root
fails with EUSAGE and the docs workflow's build job is red on main and on
every PR touching skiplang/**/ts/**/src/** (e.g. #1711).

Regenerated with `npm install --package-lock-only`. Validated with
`npm ci --ignore-scripts --no-audit --no-fund --dry-run` at the root
(passes now, EUSAGE on unmodified main) and `npm ci --dry-run` in www/.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
mbouaziz added a commit that referenced this pull request Nov 19, 2026
…1713)

## Summary

Regenerates the root `package-lock.json` so it satisfies all workspace
`package.json` files. This un-breaks the `docs` workflow's `build` job,
which has been red on `main` and on PRs since the dependabot bumps below
landed.

## Root cause

Dependabot commits bumped dependency ranges in workspace examples
without a matching root lock update:

- `examples/cache_invalidation/edge_service/package.json`: `@types/node
^26.6.6`, `typescript ^6.0.3`, `eslint 10.15.0` (e607811 and
follow-ups)
- `examples/blogger/reactive_service/package.json`: similar bumps

The root lock still pinned `@types/node 20.19.9` / `typescript 5.9.3`
under those workspaces, so `npm ci` at the repo root fails with:

```
npm error code EUSAGE
`npm ci` can only install packages when your package.json and package-lock.json are in sync.
Invalid: lock file's @types/node@20.19.9 does not satisfy @types/node@26.6.6
Missing: eslint@10.15.0 from lock file
...
```

The docs workflow runs root `npm ci` on PRs touching `www/**`,
`skipruntime-ts/**/src/**`, or `skiplang/**/ts/**/src/**` — which is why
#1711 (touching `skiplang/prelude/ts/wasm/src/sk_runtime.ts`) showed a
red `build` check even though its CircleCI checks were all green and it
merged (docs is not a required check; required checks are the CircleCI
contexts only).

## Fix

`npm install --package-lock-only --ignore-scripts` at the root. Only
`package-lock.json` changed (+919/-162): nested entries for the bumped
example workspaces, e.g.
`examples/cache_invalidation/edge_service/node_modules/@types/node` now
26.6.6. The lock's top-level metadata (`name: "skip"`, `lockfileVersion:
3`) is unchanged — regenerated in a directory whose name differs from
the repo root, so the `name` field was explicitly restored.

## Validation

- On unmodified `main` (4b3ad39): `npm ci --ignore-scripts --no-audit
--no-fund --dry-run` fails with the EUSAGE above.
- On this branch: the same command exits 0; `npm ci --no-audit --no-fund
--dry-run` in `www/` (separate lock) also exits 0.
- End-to-end: triggered the `docs` workflow on this branch via
`workflow_dispatch` — the `build` job (root `npm ci`, TS package builds,
docusaurus site build) completed **success** (run 44440100236; the
`deploy` job fails on manual runs since Pages isn't configured for
`workflow_dispatch`, which is expected and unrelated).

AI assistance: prepared with Mistral Vibe; the commit carries a
Co-Authored-By trailer.
mbouaziz added a commit to SkipLabs/skjs that referenced this pull request Nov 19, 2026
…carries a Float (#1077)

Simplifies the number-literal machinery now that the Skip stdlib
provides Ryu-based `Float.toString` (shortest round-trip,
SkipLabs/skip#1288) and `Math.fmod` (SkipLabs/skip#1711):

- `jsNumberToString` / `shortestFloatDigits` are now total: Ryu's
shortest digits always read back to the same double, so the round-trip
guard is gone
- Enum constant folding carries doubles end-to-end: `EFNum(Float)`
instead of `EFNum(String)`; the literal name is produced by
`jsNumberToString` only when a member value is materialized
- JS `%` over doubles folds with `Math.fmod` (exactly the truncated
remainder with the dividend's sign, NaN cases included), replacing a
hand-rolled Sterbenz loop; `enumDoubleInt32Base` uses it too

No behavior change: full test suite passes (230 tests), and the checker
binary produces identical results to the previous one on
positive/negative enum-folding and literal-naming repros. New pins:
`jsNumberToString` unit test and enum remainder cases (`5.5 % 2 = 1.5`,
`-5.5 % 2 = -1.5`, `1e309 % 2 = NaN -> number`), verified against `tsc
--strict`. Version bumped to 1.26.3 per the every-PR rule.

Generated by Mistral Vibe (co-authored with the commit via
`Co-Authored-By: Mistral Vibe <vibe@mistral.ai>`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant