-
Notifications
You must be signed in to change notification settings - Fork 5k
Improve the performance of BigInteger
.{Max|Min}Magnitude
/Abs
& fix a edge case of TryParse
#105570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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
src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs
Outdated
Show resolved
Hide resolved
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) |
I tend not to break any existing method, as long as it's not |
There should not be difference between |
…exception thrown by TryParse.
BigInteger
.{Max|Min}Magnitude
/Abs
BigInteger
.{Max|Min}Magnitude
/Abs
& fix a edge case of TryParse
src/libraries/System.Runtime.Numerics/src/System/Number.BigInteger.cs
Outdated
Show resolved
Hide resolved
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
Close #105324
The PR is to:
BigInteger.{Max|Min}Magnitude
by changing multiple comparison operators to a singleCompareTo
callBigInteger.Abs()
by refactoring code and making the method branchless.BigInteger.TryParse
still throws instead of returningfalse
.OuterLoop
test 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.