Description
Describe the bug
Various calls to BigInteger.shl(n)
with n < 0
produced results differing from that of java.math.BigInteger
.
To Reproduce
Try calling shl
with any of the following samples:
- Results differ (-4194304 != 0) for operation: -8388608.shl(-1)
- Results differ (8 != 0) for operation: 8388608.shl(-20)
- Results differ (8 != 0) for operation: 512.shl(-6)
- Results differ (28 != 6353246884247830528) for operation: 2078458800722539264.shl(-56)
Expected behavior
Since the method doesn't document the behaviour, I assumed behaviour consistent with java.math.BigInteger
- shl(-n)
should behave the same as shr(n)
, and vice versa. Although, I have only detected this inconsistency with shl
. I don't know whether shr
has a similar issue, as my own test suite is yet to complain about it.
Platform
- JVM
Additional context
I have been hunting for a drop-in replacement for BigInteger
. After reading through some of the API docs for this one, it seems it might not have been a candidate anyway, as not()
is explicitly documented as not being consistent with Java's.