Repository navigation
Search for a root of a small or a large number at the size of one - #2067
Merged
Rafael-SOWNet merged 4 commits intoOct 22, 2026
Merged
Rafael-SOWNet merged 4 commits into
Rafael-SOWNet merged 4 commits into
Conversation
FindGoodRoot looks for an exact root. It rounded each candidate with the zero range set to 1e-6 and accepted a rational one whose power was within 1e-6 of the base, both absolutely. A root below 1e-6 became the integer 0, and 0 ^ q is within 1e-6 of a base below it, so sqrt(2/10^20), (3/10^30)^(1/3) and sqrt(i/10^20) were 0. And the rounded candidate was what it returned as the real root when no rational one held: the root of 10^12 + 1/2 was 10^6, and (2 + i/10^8)^(1/2) lost its imaginary part. The base is scaled to the size of one by an exact power of ten and the root scaled back, so sqrt(1/10^20) is 1/10^10 exactly. A candidate is rounded only to look for a rational root, which is accepted where its power is the base at the working precision; a real root is the candidate as computed. The real cube root of a negative base stays the one given: (-2/10^21)^(1/3) is -1.26e-7, as (-8)^(1/3) is -2. Fixes #2065. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
…umber-is-searched-at-the-size-of-one
…umber-is-searched-at-the-size-of-one # Conflicts: # BREAKING-CHANGES.md
The real root is the candidate as GetAllRoots computed it at the working precision, where it was made a second time from its parts for every candidate: (-27)^(1/3) allocated 8.0% more than master, sqrt(2) 1.4%. Now both are within 0.1% of master, measured per call. Part of #2065. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
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 #2065.
FindGoodRootlooks for an exact root. It rounded each candidate with the zero range set to1e-6, and it accepted a rational candidate whose power was within1e-6of the base, both absolutely. Two wrong answers followed:1e-6became the integer0, and0 ^ qis within1e-6of any base below it. Sosqrt(2/10^20),(3/10^30)^(1/3)andsqrt(i/10^20)were0.10^12 + 1/2was10^6, and(2 + i/10^8)^(1/2)lost its imaginary part.sqrt(1/10^20)is now1/10^10exactly.(-2/10^21)^(1/3)is-1.26e-7, as(-8)^(1/3)is-2.ARootOfASmallNumberTestchecks values against mpmath, exact roots that stay exact, and the two complex cases. 9 of its 12 cases fail on master. The 3 that pass aresqrt(10^30),(-8)^(1/3)and(27/8)^(2/3), which are unchanged.(1 + i/10^8)^(1/2)is asserted to twelve digits. Its modulus,1 + 5e-17, is read as1within1e-16, and that is what #1944's PR changes.Results:
🤖 Generated with Claude Code
https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura