Skip to content

fix(maths): correct precision boundary in num_digits_fast for large integers - #15790

Closed
Pankajk001 wants to merge 1 commit into
TheAlgorithms:masterfrom
Pankajk001:fix-num-digits-fast-precision
Closed

Pankajk001 wants to merge 1 commit into
TheAlgorithms:masterfrom
Pankajk001:fix-num-digits-fast-precision

Conversation

@Pankajk001

Copy link
Copy Markdown

Summary of Changes

Fixes #15759

  • Fixed floating-point precision loss in num_digits_fast() where large numbers near powers of 10 with 16+ digits (e.g., 10**16 - 1 and 9999999999999999) were rounded up by float conversion in math.log10(), returning an incorrect off-by-one count.
  • Guarded the boundary verification with if digits >= 16:, ensuring that smaller integers (< 10^15) retain full execution speed without paying unnecessary exponentiation overhead.
  • Added regression doctests for 10**16 - 1 and 9999999999999999.
  • Verified code quality and formatting with ruff check, ruff format, and pytest --doctest-modules (all passed).

@algorithms-keeper algorithms-keeper Bot added the awaiting reviews This PR is ready to be reviewed label Nov 24, 2026
@algorithms-keeper

Copy link
Copy Markdown

Closing this pull request as invalid

@Pankajk001, this pull request is being closed as none of the checkboxes have been marked. It is important that you go through the checklist and mark the ones relevant to this pull request. Please read the Contributing guidelines.

If you're facing any problem on how to mark a checkbox, please read the following instructions:

  • Read a point one at a time and think if it is relevant to the pull request or not.
  • If it is, then mark it by putting a x between the square bracket like so: [x]

NOTE: Only [x] is supported so if you have put any other letter or symbol between the brackets, that will be marked as invalid. If that is the case then please open a new pull request with the appropriate changes.

@algorithms-keeper algorithms-keeper Bot removed the awaiting reviews This PR is ready to be reviewed label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Personal Vault stores plaintext passwords and allows unsafe note paths

1 participant