/** * Add two long integers, checking for overflow. * * @param a an addend * @param b an addend * @return the sum {@code a+b} * @throws MathArithmeticException if the result can not be represented as an long * @since 1.2 */ public static long addAndCheck(long a, long b) throws MathArithmeticException { return addAndCheck(a, b, LocalizedFormats.OVERFLOW_IN_ADDITION); }
/** * Subtract two long integers, checking for overflow. * * @param a Value. * @param b Value. * @return the difference {@code a - b}. * @throws MathArithmeticException if the result can not be represented as a * {@code long}. * @since 1.2 */ public static long subAndCheck(long a, long b) throws MathArithmeticException { long ret; if (b == Long.MIN_VALUE) { if (a < 0) { ret = a - b; } else { throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b); } } else { // use additive inverse ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION); } return ret; }
int upv = ArithmeticUtils.mulAndCheck(fraction.numerator, denominator); return new Fraction (isAdd ? ArithmeticUtils.addAndCheck(uvp, upv) : ArithmeticUtils.subAndCheck(uvp, upv), ArithmeticUtils.mulAndCheck(denominator, fraction.denominator));
/** * Add two long integers, checking for overflow. * * @param a an addend * @param b an addend * @return the sum {@code a+b} * @throws MathArithmeticException if the result can not be represented as an long * @since 1.2 */ public static long addAndCheck(long a, long b) throws MathArithmeticException { return addAndCheck(a, b, LocalizedFormats.OVERFLOW_IN_ADDITION); }
/** * Add two long integers, checking for overflow. * * @param a an addend * @param b an addend * @return the sum {@code a+b} * @throws MathArithmeticException if the result can not be represented as an long * @since 1.2 */ public static long addAndCheck(long a, long b) throws MathArithmeticException { return addAndCheck(a, b, LocalizedFormats.OVERFLOW_IN_ADDITION); }
/** * Subtract two long integers, checking for overflow. * * @param a Value. * @param b Value. * @return the difference {@code a - b}. * @throws MathArithmeticException if the result can not be represented as a * {@code long}. * @since 1.2 */ public static long subAndCheck(long a, long b) throws MathArithmeticException { long ret; if (b == Long.MIN_VALUE) { if (a < 0) { ret = a - b; } else { throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b); } } else { // use additive inverse ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION); } return ret; }
/** * Subtract two long integers, checking for overflow. * * @param a Value. * @param b Value. * @return the difference {@code a - b}. * @throws MathArithmeticException if the result can not be represented as a * {@code long}. * @since 1.2 */ public static long subAndCheck(long a, long b) throws MathArithmeticException { long ret; if (b == Long.MIN_VALUE) { if (a < 0) { ret = a - b; } else { throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b); } } else { // use additive inverse ret = addAndCheck(a, -b, LocalizedFormats.OVERFLOW_IN_ADDITION); } return ret; }
int upv = ArithmeticUtils.mulAndCheck(fraction.numerator, denominator); return new Fraction (isAdd ? ArithmeticUtils.addAndCheck(uvp, upv) : ArithmeticUtils.subAndCheck(uvp, upv), ArithmeticUtils.mulAndCheck(denominator, fraction.denominator));
int upv = ArithmeticUtils.mulAndCheck(fraction.numerator, denominator); return new Fraction (isAdd ? ArithmeticUtils.addAndCheck(uvp, upv) : ArithmeticUtils.subAndCheck(uvp, upv), ArithmeticUtils.mulAndCheck(denominator, fraction.denominator));