-
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.Parse creates invalid instances from hex strings #74758
Comments
Tagging subscribers to this area: @dotnet/area-system-numerics Issue DetailsDescriptionBy design, the following expression creates an instance of BigInteger with the value of -2 Reproduction Steps
Expected behaviorOutput is Actual behaviorOutput is Regression?No response Known WorkaroundsNo response Configuration.Net version: 6.0.300 Other informationNo response
|
This bug also repro's in .NET 6. Parse is creating a Where-as casting and implicit conversion creates a |
It seems I found the cause of the bug. I've fixed it locally, but it needs to be tested. I think I'll send PR in a couple of days. |
Description
By design, the following expression creates an instance of BigInteger with the value of -2
var x = BigInteger.Parse("FFFFFFFFE", NumberStyles.HexNumber);
However, x is not equal to another instance with a value of -2.
Reproduction Steps
var x = BigInteger.Parse("FFFFFFFFE", NumberStyles.HexNumber);
var minusTwo = new BigInteger(-2);
Console.WriteLine(x);
Console.WriteLine(x == minusTwo);
Console.WriteLine(x == -2);
Expected behavior
Output is
-2
True
True
Actual behavior
Output is
-2
True
False
Regression?
No response
Known Workarounds
No response
Configuration
.Net version: 6.0.300
Operating System: Microsoft Windows 10 Pro
Architecture: x64
Other information
No response
The text was updated successfully, but these errors were encountered: