-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
BigInteger correctness regression from .NET 8 #109669
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics |
Bug looks to be in the internal span constructor and sign preservation being incorrectly tracked as |
Thanks for reporting this, @hez2010. We will fix this and backport into 9.0 servicing. @tannergooding Do you think this is limited to a small domain of values? We will need to prepare a Known Issues entry on https://github.com/dotnet/core/blob/main/release-notes/9.0/known-issues.md for this. |
In my understanding, it affects the operators An assert can fire for values with nonzero trailing blocks, but it does not result in correctness issues. But for the affected values, it can also give rise to an exception when formatting, because of invalid internal state e.g. BigInteger a = new BigInteger(MemoryMarshal.AsBytes([uint.MaxValue, 0u, 0u]), isBigEndian: true);
BigInteger or = a | a;
Console.WriteLine(or == a); // False (should be True)
Console.WriteLine(or); // System.IndexOutOfRangeException: Index was outside the bounds of the array.
// at System.Number.FormatBigInteger(Boolean targetSpan, BigInteger value, String formatString, ReadOnlySpan`1 formatSpan, NumberFormatInfo info, Span`1 destination, Int32& charsWritten, Boolean& spanSuccess)
// at System.Number.FormatBigInteger(BigInteger value, String format, NumberFormatInfo info)
// at System.Numerics.BigInteger.ToString() |
The fix was already submitted at #105456 |
Description
BigInteger produces incorrect results in .NET 9, while this doesn't repro with .NET 8 or earlier.
Reproduction Steps
Expected behavior
Actual behavior
Regression?
Yes
Known Workarounds
No
Configuration
.NET 9 rc2
Other information
No response
The text was updated successfully, but these errors were encountered: