Skip to content
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

Right-shift of certain negative BigIntegers incorrectly results in 0 #43396

Closed
slozier opened this issue Oct 14, 2020 · 4 comments
Closed

Right-shift of certain negative BigIntegers incorrectly results in 0 #43396

slozier opened this issue Oct 14, 2020 · 4 comments
Labels
area-System.Numerics bug help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@slozier
Copy link
Contributor

slozier commented Oct 14, 2020

Description

It appears that right shifting certain negative BigInteger values by 32 incorrectly results in 0.

var a = BigInteger.Parse("-18446744073709543424");
Debug.Assert(a >> 32 == (a >> 31) >> 1);

I've seen this occur for -18446744073709543424 and -79228162514264337593543917568. Appears to be related to the underlying array representation since it's possible to construct the same values in a way that the shift works.

Configuration

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100-rc.2.20479.15\

Host (useful for support):
Version: 5.0.0-rc.2.20475.5
Commit: c5a3f49

Regression?

Appears to occur on .NET Framework as well so probably a bug that's been there for a long time?

@vcsjones
Copy link
Member

/cc @tannergooding (no idea where bot for labels is)

@maryamariyan maryamariyan added untriaged New issue has not been triaged by the area owner area-System.Numerics labels Oct 14, 2020
@ghost
Copy link

ghost commented Oct 14, 2020

Tagging subscribers to this area: @tannergooding, @pgovind, @jeffhandley
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

Will look into this more, I'm guessing there is a bug in the sign propagation logic.: https://source.dot.net/#System.Runtime.Numerics/System/Numerics/BigInteger.cs,1926

@tannergooding tannergooding added bug help wanted [up-for-grabs] Good issue for external contributors and removed untriaged New issue has not been triaged by the area owner labels Jun 17, 2021
@tannergooding tannergooding added this to the Future milestone Jun 17, 2021
@wzchua
Copy link
Contributor

wzchua commented Jun 18, 2021

This is a dupe of #27358

@ghost ghost locked as resolved and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Numerics bug help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests

5 participants