package expression;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

/**
 * @author Doschennikov Nikita (me@fymio.us)
 */
public class Divide extends AbstractBinaryOperation {

    public Divide(AbstractExpression l, AbstractExpression r) {
        super(l, r);
    }

    @Override
    protected String getOperator() {
        return "/";
    }

    @Override
    protected int getPriority() {
        return 2;
    }

    @Override
    protected boolean isRightAssoc() {
        return true;
    }

    @Override
    protected int applyInt(int a, int b) {
        return a / b;
    }

    @Override
    protected BigInteger applyBi(BigInteger a, BigInteger b) {
        return a.divide(b);
    }

    @Override
    protected BigDecimal applyBd(BigDecimal a, BigDecimal b) {
        return a.divide(b, MathContext.DECIMAL128);
    }
}
