Description
When bit length of BigInteger value is greater than 2^(int.MaxValue+1) - 1, then IBinaryInteger<BigInteger>.GetShortestBitLength() can not return correct result because bit length is more than int.MaxValue.
Now IBinaryInteger<BigInteger>.GetShortestBitLength() returns incorrect negative value.
Reproduction Steps
Code:
using System.Numerics;
var l1 = 42;
var l2 = int.MaxValue;
BigInteger b = (BigInteger.One<<l1)<<l2;
var ll = 1L + l1 + l2;
Console.WriteLine(ll);
var res = ((IBinaryInteger<BigInteger>)b).GetShortestBitLength();
Console.WriteLine(res);
Expected behavior
Exception on GetShortestBitLength call. Result can not be presented in int type.
Actual behavior
output
Regression?
No
Known Workarounds
No
Configuration
The latest main branch
Other information
probably from PR #69391
cc @tannergooding
It seems fix is quite trivial, I can do it.
Description
When bit length of BigInteger value is greater than
2^(int.MaxValue+1) - 1, thenIBinaryInteger<BigInteger>.GetShortestBitLength()can not return correct result because bit length is more than int.MaxValue.Now
IBinaryInteger<BigInteger>.GetShortestBitLength()returns incorrect negative value.Reproduction Steps
Code:
Expected behavior
Exception on
GetShortestBitLengthcall. Result can not be presented ininttype.Actual behavior
output
Regression?
No
Known Workarounds
No
Configuration
The latest
mainbranchOther information
probably from PR #69391
cc @tannergooding
It seems fix is quite trivial, I can do it.