Improve the performance of BigInteger.{Max|Min}Magnitude/Abs & fix a edge case of TryParse - #105570
Merged
Merged
Conversation
Improved performance of BigInteger.{Max|Min}Magnitude/Abs/operator-
Co-Authored-By: PetSerAl <17184058+petseral@users.noreply.github.com>
BigInteger.{Max|Min}Magnitude/Abs/operator-BigInteger.{Max|Min}Magnitude/Abs
This was referenced Jul 27, 2024
karakasa
marked this pull request as ready for review
July 28, 2024 08:54
Rob-Hague
reviewed
Jul 28, 2024
Contributor
|
Interesting. [MethodImpl(MethodImplOptions.AggressiveInlining)]
private BigInteger(int n, uint[]? rgu, [ConstantExpected] bool noLengthCheck)
{
if (noLengthCheck && (rgu is not null) && (rgu.Length > MaxLength))
{
ThrowHelper.ThrowOverflowException();
}
_sign = n;
_bits = rgu;
AssertValid();
}And return new BigInteger(-1, buffer, noLengthCheck: true);Maybe we can have... [MethodImpl(MethodImplOptions.AggressiveInlining)]
internal BigInteger(int n, uint[]? rgu, [ConstantExpected] bool noLengthCheck = false) |
Contributor
Author
I tend not to break any existing method, as long as it's not |
Member
There should not be difference between |
…exception thrown by TryParse.
BigInteger.{Max|Min}Magnitude/AbsBigInteger.{Max|Min}Magnitude/Abs & fix a edge case of TryParse
This was referenced Jul 30, 2024
jeffhandley
reviewed
Mar 23, 2025
jeffhandley
approved these changes
Mar 23, 2025
Member
|
/azp run runtime-libraries-coreclr outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
This was referenced Mar 23, 2025
Member
|
@tannergooding This is a more targeted change that seems worthwhile to bring in to .NET 11. |
tannergooding
approved these changes
Sep 16, 2025
tannergooding
enabled auto-merge (squash)
September 16, 2025 19:10
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Close #105324
The PR is to:
BigInteger.{Max|Min}Magnitudeby changing multiple comparison operators to a singleCompareTocallBigInteger.Abs()by refactoring code and making the method branchless.BigInteger.TryParsestill throws instead of returningfalse.OuterLooptest covering this but it would take 1.5~2GB which may unstablize the testing environment. Feel free to notify me if you think the test should be removed. The bug is on a very rare path.