Need reviewer: JDK 8 CR for Support Integer overflow
scolebourne at joda.org
Fri Feb 3 15:23:48 UTC 2012
I prefer the method naming safeAdd/safeNegate/safeMultiply (I think
they are a lot clearer), but can live with the ones proposed (which
are somewhat linked to BigInteger/BigDecimal).
I would like to see source code comments explaining why the algorithm
works in the final version in OpenJDK. Thats because OpenJDK code is
used by everyone to read and understand what is good Java code, and
for debugging. Being given a clue to understand the algorithm is
It would be desirable to see safe increment and decrement methods as
well. These are faster than just an add/subtract (simpler
Most of the methods do not specify the arguments in the exception, but
the multiply methods do. It should be consistent one way or the other.
It may be worth considering (by testing) if methods taking one long
and one int are worthwhile. More efficient implementations of the
algorithms may be possible, but at the expense of additional API size.
Separately but related, there are missing methods in BigInteger,
longValueExact() and intValueExact()
Also see here if you haven't already:
On 2 February 2012 20:15, Roger Riggs <Roger.Riggs at oracle.com> wrote:
> There is a need for arithmetic operations that throw exceptions
> when the results overflow the representation of int or long.
> The CR is 6708398: Support integer overflow
> Please review this webrev
> <http://cr.openjdk.java.net/%7Erriggs/CR6708398/webrev/> to add static
> methods in java.lang.Math
> to support addExact(), subtractExact(), negateExact(), multiplyExact(),
> and toIntExact() for int and long primitive types.
> Thanks, Roger Riggs
More information about the core-libs-dev