public static long safeAdd(
        long op1,
        long op2
    ) {

        if (op2 == 0L) {
            return op1;
        }

        if (
            (op2 > 0)
            ? (op1 > Long.MAX_VALUE - op2)
            : (op1 < Long.MIN_VALUE - op2)
        ) {
            StringBuilder sb = new StringBuilder(32);
            sb.append("Long overflow: (");
            sb.append(op1);
            sb.append(',');
            sb.append(op2);
            sb.append(')');
            throw new ArithmeticException(sb.toString());
        }

        return op1 + op2;

    }
public static long safeAdd ( long op1 , long op2 ) { if ( op2 == 0L ) { return op1 ; } if ( ( op2 > 0 ) ? ( op1 > Long . MAX_VALUE - op2 ) : ( op1 < Long . MIN_VALUE - op2 ) ) { StringBuilder sb = new StringBuilder ( 32 ) ; sb . append ( "Long overflow: (" ) ; sb . append ( op1 ) ; sb . append ( ',' ) ; sb . append ( op2 ) ; sb . append ( ')' ) ; throw new ArithmeticException ( sb . toString ( ) ) ; } return op1 + op2 ; }
/*[deutsch]
<p>Addiert die Zahlen mit &Uuml;berlaufkontrolle. </p>

@param   op1     first operand
@param   op2     second operand
@return  sum
@throws  ArithmeticException if long-range overflows