Skip to content

fix: preserve integer arithmetic and loop dtype semantics - #9

Merged
egparedes merged 3 commits into
mainfrom
fix-arithmetic-loop-semantics
Oct 7, 2026
Merged

egparedes merged 3 commits into
mainfrom
fix-arithmetic-loop-semantics

Conversation

@egparedes

@egparedes egparedes commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Plain negative-literal remainder/floor division and integer true division bypassed dtype dispatch, boolean loop inputs lost arithmetic promotion, and loop-index conditions sent raw Python booleans to strict where calls. Route these arithmetic cases through runtime helpers and emit Python selection for conditions proven to depend only on loop indices and literals, preserving the selected branch dtype.

Preserve safe constant folding for loop bounds and assigned negative constants. Fix two latent runtime defects exposed by the wider dispatch: unsigned floor quotients below int64-min now use the documented float64 fallback without changing sign; integer true division rounds once using binary long division instead of rounding large operands first. Add behavioral, runtime, and compiled-backend regressions, update semantics documentation, and review the three intentional division golden changes.

Validation:

  • make check in the development-only environment: 960 passed, 96 skipped, 96% coverage.
  • Five fuzz seeds, strict docs build, and smoke examples/notebooks.
  • Independent semantics review approved; 179,960 exact division and normalization boundary checks, plus 4,448 backend/dtype scenarios and positioned rejection checks.
  • All 95 JAX/PyTorch compilation tests passed locally, including exact integer ratios (4m54s). CI subsequently exposed a PyTorch compiled INT64_MIN / -1 failure; that issue remains unresolved.

Tradeoff: correctly rounded integer division uses exact normalization followed by a fixed 55-step bit loop, increasing call cost and first JIT compilation time. Floating-point division retains its existing path.

Includes #8’s merged type-checker workflows. The combined local gate passes all four checkers, 960 tests, and 96% coverage; an independent merge review approved 2,392 lane comparisons and 24 rejection checks.

@egparedes
egparedes merged commit b1facfd into main Oct 7, 2026
8 of 9 checks passed
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