Skip to content

Round Log in a base, Log2, Log2P1 and Log10P1 to the digits asked for [patch] - #183

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/147-log-quotient-precision
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/147-log-quotient-precision

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Summary

Log(x, newBase, digits), Log2, Log2P1 and Log10P1 each finished with Divide(…, significantDigits). Divide returns a terminating quotient exactly and ignores the precision argument, so Log(1E5, 1E4, 1) returned 1.25, three digits for a one-digit request. These four now use DivideApproximation, which Trigonometry and Roots already use for the same reason.

Tests

  • TestLogInABaseRoundsATerminatingQuotientToTheDigitsAskedFor pins Log(1E5, 1E4, n) at 1, 2 and 3 digits (1, 1.3, 1.25; rounding is half away from zero), plus the non-terminating Log(1E7, 1E4, 2) = 1.8.
  • TestDividedLogarithmsNeverReturnMoreDigitsThanAskedFor sweeps 1 to 64 at 1 to 4 digits through all four methods.

Both tests fail on main and pass with this change. In a probe over integers up to 2000 and thousandths up to 20, only the chosen-base path produced a terminating quotient, so for Log2, Log2P1 and Log10P1 the sweep is a guard rather than a reproduction. Those three are changed to keep the four call sites consistent, as the issue asks.

Full suite: 550 passed, 0 failed.

Fixes #147


Generated by Claude Code

… [patch]

Each finished with Divide, which returns a terminating quotient exactly and
ignores significantDigits, so Log(1E5, 1E4, 1) returned 1.25. Use
DivideApproximation, as Trigonometry and Roots already do.

Fixes #147

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4sAxuwubJA58cavro
@sonarqubecloud

sonarqubecloud Bot commented Nov 1, 2026

Copy link
Copy Markdown

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.

Log(x, base, digits), Log2, Log2P1 and Log10P1 return more digits than requested when the quotient terminates: Log(1e5, 1e4, 1) returns 1.25

1 participant