fix(math fns) Math.min/Math.max truncating Float (and String) arguments#136
Open
arthurmaciel wants to merge 2 commits into
Open
fix(math fns) Math.min/Math.max truncating Float (and String) arguments#136arthurmaciel wants to merge 2 commits into
arthurmaciel wants to merge 2 commits into
Conversation
Math.min / Math.max are polymorphic (`a -> a -> a`, "any comparable type" — Sky.Core.Math), but the Go backend coerced their arguments through AsInt: the P8 typed-companion pass emitted rt.Math_minT(rt.AsInt(x), rt.AsInt(y)) (typedKernelArgCoerce + typedKernelLiterals), and the polymorphic fallback rt.Math_min/rt.Math_max also compared via AsInt. So a Float Math.min/max TRUNCATED to Int — e.g. the range of [0.4 … 1.3] collapsed to 0..1, mis-scaling every Std.Ui.Chart sparkline and heatmap (the heatmap rendered a single cell instead of the full grid). Strings were meaningless too. Fix: (1) rt.Math_min/rt.Math_max compare via skyLessThan (the existing polymorphic comparator used by List_sortBy) instead of AsInt; (2) drop Math.min/Math.max from typedKernelArgCoerce + typedKernelLiterals so they lower to the (now-correct) polymorphic kernel — the use-site coercion narrows the result. Math.abs stays (its Sky type is Int -> Int, so AsInt is correct). Regression tests cover Float, Int, and String min/max.
The bundled console (sky-bundled/console/) uses Std.Ui.Chart, so its committed generated Go (runtime-go/rt/console_app/main.go) now lowers Math.min/Math.max to the polymorphic rt.Math_min/rt.Math_max instead of the Int companion. Regenerated via scripts/regenerate-console.sh so the inline-copy drift check passes.
Owner
|
it makes sense, yes Go's side of |
arthurmaciel
added a commit
to arthurmaciel/sky
that referenced
this pull request
Jun 20, 2026
equiv-render.sh + two normalisers add STRICT render-equivalence for the UI shapes the examples-sweep's weak modes (live=scenario-boot, tui=pty-no-crash) miss. live (equiv_normalize_html.py): serve both, GET /, extract #sky-root, byte-diff after canonicalising legitimate implementation-detail differences — sky-id separators, attribute order, event wire-encoding, pseudo/mq/anim/tr style-delivery — and masking SVG chart coords (known Go float-truncation, PR anzellai#136). The backends are committed to BEHAVIOURAL parity, not byte parity, so the test compares what the user sees. Verified: 26-ui-showcase → 0-line diff (structural parity); a textarea/badge/structure regression would re-surface. tui (equiv_tui_grid.py): capture the initial frame in a fixed 80xN pty, render via pyte to a styled cell grid (char + fg/bg/bold/italic/underline), diff. Catches layout + styling. Verified it detects the current 24 divergences (collapses to ~0 after the Tui renderer-parity fixes land). Normalisers verified against real both-backend captures; full build-harness run + CI wiring deferred until the Tui fixes land (commit green, not known-red) and to avoid racing the shared cargo target while the Tui implementer builds.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Math.min/Math.maxare polymorphic —a -> a -> a("any comparable type",per
Sky.Core.Math). But the Go backend coerced their arguments throughAsInt:rt.Math_minT(rt.AsInt(x), rt.AsInt(y))(
typedKernelArgCoerce+typedKernelLiterals), andrt.Math_min/rt.Math_maxalso compared viaAsInt.So a Float
Math.min/maxtruncated to Int. The range of[0.4 … 1.3]collapses to
0..1, which mis-scales everyStd.Ui.Chartsparkline and heatmap —the heatmap renders a single cell instead of the full grid. String args were
meaningless too.
Before / After
Fix
rt.Math_min/rt.Math_maxcompare viaskyLessThan(the polymorphiccomparator already used by
List_sortBy) instead ofAsInt.Math.min/Math.maxfromtypedKernelArgCoerce+typedKernelLiteralsso they lower to the now-correct polymorphic kernel; the use-site coercion
narrows the result.
runtimeGoSourcefallback.Math.absis intentionally left untouched — its Sky type isInt -> Int, soAsIntis correct.Tests
runtime-go/rt/math_minmax_poly_test.gocovers Float / Int / Stringmin/max.go test ./rt/passes.Related — Elm conformance
Sky.Core.Mathmirrors Elm'sBasics; thisrestores
min/maxto Elm's polymorphiccomparable -> comparable -> comparable.It may be worth a broader review of Sky's conformance to Elm
Basics— forexample, Elm's
abs : number -> numberacceptsFloat, whereas Sky'sabsiscurrently
Int -> Int.