Carry Pi, Tau and E at 150 correctly rounded digits, and add Ln2 and Ln10 [minor] - #84
Merged
Merged
Conversation
…Ln10 [minor] Pi carried 26 significant digits, Tau 25 and E 41, all of them fewer than MinimumDivisionPrecision (50), so any expression mixing a constant with a quotient was capped at the constant's precision with nothing to indicate it. Pi was also truncated rather than rounded: the 27th significant digit of pi is 8, so a 26 digit pi ends 434, and the literal ended 433. Nothing pinned Tau == Pi * 2 either, and the two literals did not use the same rounding rule as each other. Carry all three at 150 significant digits, correctly rounded, and add Ln2 and Ln10 at the same precision for the exp/log work. 150 matches what ktsu.Semantics standardises on for the factors it derives from pi, so the two libraries cannot disagree about it, and it leaves room for argument reduction, which cannot be more accurate than the constant it reduces by. Each constant is its own literal, never computed from a sibling, so an error in one cannot reach the others. Multiplication is exact, so a product involving a 150 digit constant carries at least 150 digits. PiTo(n), ETo(n), TauTo(n), Ln2To(n) and Ln10To(n) let a caller that only wants fifteen ask for fifteen, rounded half away from zero and cached per requested precision. PreciseNumberConstantTests checks every constant digit for digit against an independent series: Machin's formula for Pi and Tau, sum 1/k! for E, and artanh series for Ln2 and Ln10. It also pins Tau as exactly Pi doubled, pins that no constant falls below MinimumDivisionPrecision, and pins pi/3 past the 24th digit, where the old literal went wrong. The three tests in PreciseNumberTests that compared each constant against a second copy of its own literal are superseded by those. Pi changes value in its 26th significant digit and gains 124 more, which is an observable change to a public constant, hence the minor bump. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NSqQkFe6PqeB4fuVt272j5
SonarCloud's MSTEST0037 on the new constant test: the dedicated assertion reports the bound and the actual digit count on failure, where Assert.IsTrue only reports false. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NSqQkFe6PqeB4fuVt272j5
|
This was referenced Sep 17, 2026
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 #79
The three problems
Picarried 26 significant digits,Tau25 andE41, against aMinimumDivisionPrecisionof 50. Any expression mixing a constant with a quotient was capped at the constant's precision with nothing to indicate it —Pi / 3was wrong from its 24th digit on.Piwas truncated, not rounded. π's 27th significant digit is 8, so a correctly rounded 26-digit π ends…434. The literal ended…433.Tauwas rounded, so the two constants did not use the same rule as each other.Tau == Pi * 2. They are independent literals that happened to agree to the shorter one's precision.The change
Pi,Tau,E, plus newLn2andLn10, are each carried atConstantPrecision(150) significant digits, correctly rounded. 150 matches whatktsu.Semanticsstandardises on for the factors it derives from π, so the two libraries cannot disagree about π, and it leaves room for argument reduction, which cannot be more accurate than the constant it reduces by.Each constant is its own literal, never computed from a sibling, so an error in one cannot propagate to the others.
Multiplication is exact, so a product involving a 150-digit constant carries at least 150 digits.
PiTo(n),ETo(n),TauTo(n),Ln2To(n)andLn10To(n)let a caller that only wants fifteen ask for fifteen; they round half away from zero and cache per requested precision. No transcendental function in the library readsPitoday, so nothing needed rewiring to the new accessors — that lands with the exp/log work the issue anticipates.One wrinkle worth knowing: ln(10)'s 150th significant digit is a zero, which the constructor strips along with any other trailing zero, so
Ln10.SignificantDigitsreads 149 for the same 150-digit-accurate value. It is documented on the property and pinned by a test.Tests
New
PreciseNumber.Test/PreciseNumberConstantTests.cschecks every constant digit for digit against an independent computation, never against a second copy of the literal — Machin's formula forPiandTau,sum 1/k!forE, artanh series forLn2andLn10, all inBigIntegerfixed point with 40 guard digits. It also pinsTauas exactlyPidoubled, pins that no constant falls belowMinimumDivisionPrecision, pinsπ/3past the 24th digit, and coversPiToat every precision from 1 to 150 along with the cache, the clamp, and the argument validation.The three tests in
PreciseNumberTeststhat compared each constant against a second copy of its own literal are superseded by these and have been removed, with a comment left in their place pointing at the new file.Proof the tests catch the bug: with the old literals temporarily restored (new API kept so it still compiles), 8 of the 14 new tests fail, one per problem above —
With the fix in place the whole suite passes: 277/277, Debug and Release, 0 warnings across all four target frameworks. Benchmarks were not re-run — this changes constant values and adds members, not the arithmetic internals they measure, and none of the benchmark classes touch
Pi,TauorE.Compatibility
Pichanges value in its 26th significant digit and gains 124 more. Strictly more accurate, but an observable change to a public constant, so the commit is tagged[minor]rather than[patch]. Any downstream test pinning the old 26-digit literal will fail, which is the correct outcome — that literal was wrong in its last place.🤖 Generated with Claude Code
https://claude.ai/code/session_01NSqQkFe6PqeB4fuVt272j5
Generated by Claude Code