Java Code Examples for org.apache.commons.math3.exception.util.LocalizedFormats#OVERFLOW_IN_MULTIPLICATION

The following examples show how to use org.apache.commons.math3.exception.util.LocalizedFormats#OVERFLOW_IN_MULTIPLICATION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastMath.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Multiply two numbers, detecting overflows.
 * @param a first number to multiply
 * @param b second number to multiply
 * @return a*b if no overflows occur
 * @exception MathArithmeticException if an overflow occurs
 * @since 3.4
 */
public static int multiplyExact(final int a, final int b) {
    if (((b  >  0)  && (a > Integer.MAX_VALUE / b || a < Integer.MIN_VALUE / b)) ||
        ((b  < -1)  && (a > Integer.MIN_VALUE / b || a < Integer.MAX_VALUE / b)) ||
        ((b == -1)  && (a == Integer.MIN_VALUE))) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b);
    }
    return a * b;
}
 
Example 2
Source File: FastMath.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Multiply two numbers, detecting overflows.
 * @param a first number to multiply
 * @param b second number to multiply
 * @return a*b if no overflows occur
 * @exception MathArithmeticException if an overflow occurs
 * @since 3.4
 */
public static long multiplyExact(final long a, final long b) {
    if (((b  >  0l)  && (a > Long.MAX_VALUE / b || a < Long.MIN_VALUE / b)) ||
        ((b  < -1l)  && (a > Long.MIN_VALUE / b || a < Long.MAX_VALUE / b)) ||
        ((b == -1l)  && (a == Long.MIN_VALUE))) {
            throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b);
        }
        return a * b;
}
 
Example 3
Source File: FastMath.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Multiply two numbers, detecting overflows.
 * @param a first number to multiply
 * @param b second number to multiply
 * @return a*b if no overflows occur
 * @exception MathArithmeticException if an overflow occurs
 * @since 3.4
 */
public static int multiplyExact(final int a, final int b) {
    if (((b  >  0)  && (a > Integer.MAX_VALUE / b || a < Integer.MIN_VALUE / b)) ||
        ((b  < -1)  && (a > Integer.MIN_VALUE / b || a < Integer.MAX_VALUE / b)) ||
        ((b == -1)  && (a == Integer.MIN_VALUE))) {
        throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b);
    }
    return a * b;
}
 
Example 4
Source File: FastMath.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Multiply two numbers, detecting overflows.
 * @param a first number to multiply
 * @param b second number to multiply
 * @return a*b if no overflows occur
 * @exception MathArithmeticException if an overflow occurs
 * @since 3.4
 */
public static long multiplyExact(final long a, final long b) {
    if (((b  >  0l)  && (a > Long.MAX_VALUE / b || a < Long.MIN_VALUE / b)) ||
        ((b  < -1l)  && (a > Long.MIN_VALUE / b || a < Long.MAX_VALUE / b)) ||
        ((b == -1l)  && (a == Long.MIN_VALUE))) {
            throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_MULTIPLICATION, a, b);
        }
        return a * b;
}