Skip to content

MOD: match Excel large quotient limit - #2979

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Harrison-Booth:gc-fix-2657
Oct 31, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Harrison-Booth:gc-fix-2657

Conversation

@Harrison-Booth

@Harrison-Booth Harrison-Booth commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Makes MOD return #NUM! when ABS(number/divisor) >= 1.1259E12, matching Excel 16.0, and adds the function's docs/function-parity.md row. The boundary and large quotient values are covered by regression cases.

Verification: Expected results come from the Excel 16.0 COM observations documented in the original combined PR. cargo fmt --check passed locally. Per task instructions, Rust tests were not run locally; fork CI runs them.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • The MOD function now returns #NUM! when the absolute number-to-divisor quotient is at least 1.1259E12. Quotients below this limit continue to return the remainder, and a zero divisor continues to return #DIV/0!.
  • Documentation
    • Updated the worksheet-function parity reference to reflect the MOD quotient limit.

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 75f7056 and 5c31d7a.

Files selected for processing: 3
  • crates/functions/src/math.rs
  • crates/functions/src/math/tests.rs
  • docs/function-parity.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

MOD now returns #NUM! when the absolute quotient reaches the stated limit, while retaining the zero-divisor check. Tests and function parity documentation cover the threshold behavior.

Changes: MOD Quotient Limit

Layer / File(s) Summary
Quotient check and validation
crates/functions/src/math.rs, crates/functions/src/math/tests.rs, docs/function-parity.md
modulo returns #NUM! when abs(x / d) >= 1.1259e12, after checking for a zero divisor. Tests cover errors at and above the limit and successful remainders below it. The parity document records the Excel 16.0 behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: aiongg, echelon

Merge Risk: Minimal · up to 5c31d

No actionable merge-blocking risk remains in the reviewed change.

Architecture risk: Low · up to 5c31d

The change affects 2 systems.

Changed systems: crates, docs

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 2 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/functions/src/math.rs: modulo adds a quotient-magnitude check: when abs(x / d) >= 1.1259e12, it returns CellError::Num; the zero-divisor check still occurs first.
  • observed — Modified behavior in crates/functions/src/math/tests.rs: Replaces mod_tiny_divisor_stays_in_range, which checked that tiny-divisor results were zero or had the divisor’s sign and a smaller magnitude, with mod_quotient_limit. The new test expects #NUM! for eight cases whose absolute quotient is at least 1.1259E12, and checks successful remainders just below the limit and for a large multiple with remainder 3.
  • observed — Modified behavior in docs/function-parity.md: The review and update dates change from October 15 and October 25 to October 30, 2026, and the change description adds a MOD edge-case parity row.
  • observed — Modified behavior in docs/function-parity.md: Adds the MOD quotient limit: Excel 16.0 returns #NUM! when ABS(number/divisor) >= 1.1259E12; lower quotients retain the remainder.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the primary change: updating MOD to match Excel's large quotient limit.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
⚔️ Resolve merge conflicts: 💡
  • Resolve merge conflict in branch gc-fix-2657
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@echelon

echelon commented Oct 31, 2026

Copy link
Copy Markdown
Member

Thanks for splitting #2657! Could you close #2657 (or say which parts it still carries)? While both are open they overlap, so we'll land this as soon as #2657 is closed.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 8069ad3 into storytold:main Oct 31, 2026
1 check passed
@echelon

echelon commented Oct 31, 2026

Copy link
Copy Markdown
Member

Landed in main (67e39fa). Thank you for the contribution, @Harrison-Booth, and for splitting and following up on the review!

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.

3 participants