Skip to content

Fix division by zero#117

Merged
raviqqe merged 1 commit into
mainfrom
bug/div-to-nan
Jul 7, 2026
Merged

Fix division by zero#117
raviqqe merged 1 commit into
mainfrom
bug/div-to-nan

Conversation

@raviqqe

@raviqqe raviqqe commented Jul 7, 2026

Copy link
Copy Markdown
Owner

No description provided.

@codspeed-hq

codspeed-hq Bot commented Jul 7, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 41 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing bug/div-to-nan (0bcd11a) with main (5cc30e0)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@raviqqe
raviqqe marked this pull request as ready for review July 7, 2026 01:36
Copilot AI review requested due to automatic review settings July 7, 2026 01:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Float62’s division behavior to avoid undefined/panicking integer operations when dividing by zero, and aligns integer-division-by-zero results with IEEE-754 float semantics (±∞ for nonzero / 0, NaN for 0 / 0).

Changes:

  • Prevent modulo-by-zero by guarding the integer fast-path with y != 0 before x % y.
  • For integer division by zero, fall back to float division (x as f64 / y as f64) to produce ±∞/NaN instead of a hardcoded NaN.
  • Update division-by-zero tests to assert ±∞ and NaN outcomes.
Comments suppressed due to low confidence (1)

src/f62.rs:305

  • Float62::from_integer only reliably encodes 63-bit signed integers (see box_integer docs). In the integer fast-path, x / y can produce a quotient outside that range (e.g. x == -(1<<62) and y == -1 yields 1<<62). Boxing that value wraps and decodes to the wrong integer. Consider range-checking the quotient and falling back to float when it is not representable as an integer payload (and add a regression test for this boundary case).
        if y != 0 && x % y == 0 {
            Self::from_integer(x / y)
        } else {
            Self::from_float(x as f64 / y as f64)
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@raviqqe
raviqqe merged commit 95f8845 into main Jul 7, 2026
14 checks passed
@raviqqe
raviqqe deleted the bug/div-to-nan branch July 7, 2026 01:49
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