Round exact quotients of approximations to the requested digits [patch] - #141
Merged
Merged
Conversation
Divide returns a terminating quotient exactly. Asin(±1), Atan2(y, 0), DegreesToRadians and RootN(x, -n) divided a value already rounded to a wider working precision, so when the quotient terminated they returned the guard digits too, and those digits were wrong: Asin(1, 5) gave 1.570796326794895 and RootN(1.0486, -2, 4) gave 0.9765625. Add DivideApproximation, which divides at working precision and then rounds to significantDigits, and use it on those paths and on the other approx / approx paths (Tan, TanPi, AsinPi, AcosPi, AtanPi, RadiansToDegrees). RootN(x, -n) now takes the inner root with guard digits. Fixes #121 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014jNTPLxThrQnZyafw1CZ1p
The general paths of AsinPi and AcosPi and all of TanPi had no test, which left the new DivideApproximation call sites there uncovered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014jNTPLxThrQnZyafw1CZ1p
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #121
What changed
Divide(a, b, sd)returns a terminating quotient exactly and doesn't round it. Several paths divided a value that was already rounded to a wider working precision, most oftenPiTo(working). When that quotient terminated, the caller got the guard digits back as well, and those digits were wrong.A new private helper,
DivideApproximation(numerator, denominator, working, sd), divides at working precision and then callsReduceSignificance(sd). It is now used on:Asinat ±1,Atan2withx = 0,DegreesToRadians, andRootNwithn < 0. The inner root ofRootN(x, -n)is now also computed withRootGuardDigits, so the reciprocal comes from an unrounded root.TanandTanPi(sin/cos),AsinPi,AcosPi,AtanPiandRadiansToDegrees.Tests
Asin(±1, 5)1.570796326794895±1.5708Atan2(±1, 0, 5)1.570796326794895±1.5708DegreesToRadians(180, 5)3.141592653589793.1416DegreesToRadians(90, 5)1.5708RootN(1.0486, -2, 4)0.97656250.9766These cases are in
TestExactQuotientsOfApproximatePiStillRoundToTheRequestedDigitsandTestNegativeDegreeRootRoundsTheReciprocalOfAnUnroundedRoot. Both tests failed onmainand pass with the fix. The full suite passes: 436 of 436.This PR is independent of #140 (the Exp2 guard digits). Both come from the same precision-contract audit, but they touch different files.
🤖 Generated with Claude Code
https://claude.ai/code/session_014jNTPLxThrQnZyafw1CZ1p
Generated by Claude Code