diff --git a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs index f58c9877d3d53..b3355ff68678c 100644 --- a/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs +++ b/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs @@ -546,7 +546,7 @@ private BigInteger(Span value) if ((length == 0) || ((int)value[length - 1] >= 0)) { - // We ne need to preserve the sign bit + // We need to preserve the sign bit length++; } Debug.Assert((int)value[length - 1] < 0); diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/op_and.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/op_and.cs index 86bc8b59c0d29..235d75d44d7c9 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/op_and.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/op_and.cs @@ -120,6 +120,22 @@ public static void RunAndTests() } } + [Fact] + public void Issue109669() + { + // Operations on numbers whose result is of the form 0xFFFFFFFF 00000000 ... 00000000 + // in two's complement. + + Assert.Equal(-4294967296, new BigInteger(-4294967296) & new BigInteger(-1919810)); + Assert.Equal(-4294967296, new BigInteger(-4042322161) & new BigInteger(-252645136)); + Assert.Equal(-4294967296, new BigInteger(-8589934592) | new BigInteger(-21474836480)); + + BigInteger a = new BigInteger(MemoryMarshal.AsBytes([uint.MaxValue, 0u, 0u]), isBigEndian: true); + Assert.Equal(a, a & a); + Assert.Equal(a, a | a); + Assert.Equal(a, a ^ 0); + } + [Fact] public static void RunAndTestsForSampleSet1() {