Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError

Dmitry Nadezhin Dmitry.Nadezhin at Sun.COM
Tue Oct 20 04:03:19 UTC 2009

I want to make comments to this change from point of view of the post
"BigInteger.bitLength() can return negative results".

Suppose that the range of valid BigInteger is restiricted either to
[-2^Integer.MAX_VALUE , 2^Integer.MAX_VALUE-1]
or to
[-2^Integer.MAX_VALUE+1, 2^Integer.MAX_VALUE-1].

In this case the exact result of x.shiftRight(Integer.MIN_VALUE)
will be 0 for x==0;
will be out of BigInteger range for any x != 0.

The exact result of x.shiftLeft(Integer.MIN_VALUE)
will be 0 for any valid x >= 0;
and will be -1 for any valid x < 0.

So it seems to me that x.shiftLeft(Integer.MIN_VALUE) should never throw 
and x.shiftRight(Integer.MIN_VALUE) should throw ArithmeticException 
only when x is nonzero.


More information about the core-libs-dev mailing list