Skip to content

Correct digit counts near powers of ten with exact integer bounds - #2776

Open
pralav-25 wants to merge 1 commit into
keon:mainfrom
pralav-25:fix/exact-digit-boundaries
Open

pralav-25 wants to merge 1 commit into
keon:mainfrom
pralav-25:fix/exact-digit-boundaries

Conversation

@pralav-25

@pralav-25 pralav-25 commented Sep 25, 2026 •

Copy link
Copy Markdown

num_digits(10**20 - 1) currently returns 21 because log10 rounds the value to 20.0. This also affects negative values near powers of ten.

Keep the logarithmic estimate, then correct it using exact integer comparisons against powers of ten. Add positive and negative boundary tests through 5,000 digits, beyond Python's default integer-to-string limit, and an exhaustive small-integer string oracle. Update the complexity description to account for big-integer operations.

Validation: 617 tests pass; 480 documentation examples pass (one existing skip); repository Ruff checks pass.

Prepared with AI assistance and verified locally against the stated oracles.

Summary by CodeRabbit

  • Bug Fixes
    • Improved digit counting for large integers, including values near powers of ten. Results now correctly reflect the number of digits for positive and negative values, while zero continues to be handled separately.
    • Added coverage for boundary values and small integers to verify consistent digit counts across a wide range of inputs.

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 4c5029c8-cd75-43b4-9eb6-5f7c959d2969

📥 Commits

Reviewing files that changed from the base of the PR and between bd1d152 and 330a6e1.

📒 Files selected for processing (2)
  • algorithms/math/num_digits.py
  • tests/test_num_digits_boundaries.py

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

num_digits now corrects its logarithmic estimate by comparing the input with powers of ten. New tests cover signed values around powers of ten and compare results for integers from -2000 through 2000.

Changes

Digit Count Correction

Layer / File(s) Summary
Estimate correction and validation
algorithms/math/num_digits.py, tests/test_num_digits_boundaries.py
The function adjusts its logarithmic estimate using integer comparisons. The documentation describes digit-dependent time and space bounds. Tests cover signed powers-of-ten boundaries and small integers.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 330a6

Signed values around powers of ten return the expected digit counts in checks through 5,000 digits, and the added tests cover these boundaries and small integers. No actionable merge risk remains from this review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 main change: correcting digit counts near powers of ten with exact integer bounds.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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

This branch has not been deployed

No deployments
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