first commit

This commit is contained in:
me
2026-04-08 21:25:17 +03:00
parent 3681b8eccd
commit 371b14c5e3
173 changed files with 14126 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
package expression.exceptions;
import expression.AbstractBinaryOperation;
import expression.AbstractExpression;
import expression.OverflowException;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* @author Doschennikov Nikita (me@fymio.us)
*/
public class CheckedSubtract extends AbstractBinaryOperation {
public CheckedSubtract(AbstractExpression l, AbstractExpression r) { super(l, r); }
@Override protected String getOperator() { return "-"; }
@Override protected int getPriority() { return 1; }
@Override protected boolean isRightAssoc() { return true; }
@Override
protected int applyInt(int a, int b) {
int result = a - b;
if (((a ^ b) & (a ^ result)) < 0) {
throw new OverflowException("subtraction");
}
return result;
}
@Override protected BigInteger applyBi(BigInteger a, BigInteger b) { return a.subtract(b); }
@Override protected BigDecimal applyBd(BigDecimal a, BigDecimal b) { return a.subtract(b); }
}