Skip to content

Preserve remap results when float products overflow or underflow - #81

Merged
wolph merged 1 commit into
wolph:developfrom
fbirds5230:fix/remap-float-product
Nov 27, 2026
Merged

wolph merged 1 commit into
wolph:developfrom
fbirds5230:fix/remap-float-product

Conversation

@fbirds5230

Copy link
Copy Markdown
Contributor

remap(1e200, 0.0, 1e200, 0.0, 1e200) returns inf instead of 1e200. The same identity mapping at 1e-200 returns zero. In both cases, the intermediate multiplication loses the value before the range division can scale it back.

For finite offsets and ranges, calculate that quotient with Fraction only when the float product overflows or rounds to zero, then round it once back to a float. Simply dividing first can still double-round values near the smallest subnormal, so the tests include those boundaries and ties to zero. Fraction is imported only in this fallback.

Ordinary float calculations keep their existing evaluation order. Integer floor division, Decimal promotion, empty-range errors and nonfinite inputs are unchanged. If the quotient itself is too large for a float, the original infinity arithmetic is retained.

The regression cases cover both signs, shifted and descending ranges, extreme factors in either order, and subnormal rounding. Expected values come from exact fractions of the input floats. A changelog entry and two public API examples are included.

Validation on Linux:

  • Before the fix: 13 failing cases and 12 passing controls. All 25 pass with the fix.
  • Original tox matrix on CPython 3.10–3.15 and PyPy 3.10/3.11: 504 passed per interpreter, no skips, and 100% statement and branch coverage. The separate coverage environment also passes.
  • Ruff lint/format, Mypy, basedpyright, Pyrefly, Codespell and the Sphinx build with warnings treated as errors pass.
  • uv build and Twine checks pass. The wheel contains the exact tested source.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T01:24:48.583334Z 46b3461 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@wolph
wolph merged commit d43a5ee into wolph:develop Nov 27, 2026
18 checks passed
wolph added a commit that referenced this pull request Nov 27, 2026
@wolph

wolph commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Thank you for the fix and the thorough tests! I've added two small changelog commits on top (c3a0a5c, 4428c6b) that credit you and list the other results that change.

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.

2 participants