@Override final long divide(DecimalArithmetic arithmetic, long uDecimalDividend, long uDecimalDivisor) { throw new ArithmeticException( "Division by zero: " + arithmetic.toString(uDecimalDividend) + " / " + arithmetic.toString(uDecimalDivisor)); }
/** * Returns the special division case if it is one and null otherwise. * * @param arithmetic the arithmetic object * @param uDecimalDividend the dividend * @param uDecimalDivisor the divisor * @return the special case if it is one and null otherwise */ static final SpecialDivisionResult getFor( DecimalArithmetic arithmetic, long uDecimalDividend, long uDecimalDivisor) { // NOTE: this must be the first case because 0/0 must also throw an // exception! if (uDecimalDivisor == 0) { return DIVISOR_IS_ZERO; } if (uDecimalDividend == 0) { return DIVIDEND_IS_ZERO; } final long one = arithmetic.one(); if (uDecimalDivisor == one) { return DIVISOR_IS_ONE; } if (uDecimalDivisor == -one) { return DIVISOR_IS_MINUS_ONE; } if (uDecimalDividend == uDecimalDivisor) { return DIVISOR_EQUALS_DIVIDEND; } if (uDecimalDividend == -uDecimalDivisor) { return DIVISOR_EQUALS_MINUS_DIVIDEND; } return null; }
@Override final long divide(DecimalArithmetic arithmetic, long uDecimalDividend, long uDecimalDivisor) { return -arithmetic.one(); }
@Override final long divide(DecimalArithmetic arithmetic, long uDecimalDividend, long uDecimalDivisor) { return arithmetic.negate(uDecimalDividend); // we must go through // arithmetic because // overflow is possible }