Code review request for 6371401: java.math.BigInteger.shift(Integer.MIN_VALUE) throws StackOverflowError (original) (raw)
Joseph D. Darcy Joe.Darcy at Sun.COM
Tue Oct 20 17:22:42 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 ]
Dmitry Nadezhin wrote:
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.MAXVALUE , 2^Integer.MAXVALUE-1] or to [-2^Integer.MAXVALUE+1, 2^Integer.MAXVALUE-1].
Which is not the case today because BigInteger allows the creation of partially overflowed values, values so large that various internal counters in the class overflow or otherwise misbehave.
In this case the exact result of x.shiftRight(Integer.MINVALUE) will be 0 for x==0; will be out of BigInteger range for any x != 0.
The exact result of x.shiftLeft(Integer.MINVALUE) 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.MINVALUE) should never throw ArithmeticException
and x.shiftRight(Integer.MINVALUE) should throw ArithmeticException only when x is nonzero.
That is arguably more correct, but in my estimation screening out MIN_VALUE as an unsupported value is reasonable.
If an when BigInteger is made robust in the face of huge values, these decisions and be reexamined.
-Joe
- 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 ]