Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError (original) (raw)
Dmitry Nadezhin Dmitry.Nadezhin at Sun.COM
Tue Oct 20 04:03:19 UTC 2009
- Previous message: Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError
- Next message: Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ArithmeticException and x.shiftRight(Integer.MIN_VALUE) should throw ArithmeticException only when x is nonzero.
-Dima
- Previous message: Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError
- Next message: Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]