Android Utililty Methods Long Overflow Check

List of utility methods to do Long Overflow Check

Description

The list of methods to do Long Overflow Check are organized into topic(s).

Method

longaddAndCheck(long a, long b)
Add two long integers, checking for overflow.
return ArithmeticUtils.addAndCheck(a, b,
        LocalizedFormats.OVERFLOW_IN_ADDITION);
longaddAndCheck(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;
...
longmulAndCheck(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;
...
longsubAndCheck(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;