List of utility methods to do Long Overflow Check
long | addAndCheck(long a, long b) Add two long integers, checking for overflow. return ArithmeticUtils.addAndCheck(a, b,
LocalizedFormats.OVERFLOW_IN_ADDITION);
|
long | addAndCheck(long a, long b, Localizable pattern) Add two long integers, checking for overflow. long ret; if (a > b) { ret = addAndCheck(b, a, pattern); } else { if (a < 0) { if (b < 0) { if (Long.MIN_VALUE - b <= a) { ret = a + b; ... |
long | mulAndCheck(long a, long b) Multiply two long integers, checking for overflow. long ret; if (a > b) { ret = mulAndCheck(b, a); } else { if (a < 0) { if (b < 0) { if (a >= Long.MAX_VALUE / b) { ret = a * b; ... |
long | subAndCheck(long a, long b) Subtract two long integers, checking for overflow. long ret; if (b == Long.MIN_VALUE) { if (a < 0) { ret = a - b; } else { throw new MathArithmeticException( LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b); } else { ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION); return ret; |