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,32 @@
package expression.exceptions;
import java.math.BigDecimal;
import java.math.BigInteger;
import expression.*;
/**
* @author Doschennikov Nikita (me@fymio.us)
*/
public class CheckedMultiply extends AbstractBinaryOperation {
public CheckedMultiply(AbstractExpression l, AbstractExpression r) { super(l, r); }
@Override protected String getOperator() { return "*"; }
@Override protected int getPriority() { return 2; }
@Override protected boolean isRightAssoc() { return false; }
@Override
protected int applyInt(int a, int b) {
if (a == 0 || b == 0) return 0;
if (a == Integer.MIN_VALUE && b == -1) throw new OverflowException("multiplication");
if (b == Integer.MIN_VALUE && a == -1) throw new OverflowException("multiplication");
int result = a * b;
if (result / a != b) {
throw new OverflowException("multiplication");
}
return result;
}
@Override protected BigInteger applyBi(BigInteger a, BigInteger b) { return a.multiply(b); }
@Override protected BigDecimal applyBd(BigDecimal a, BigDecimal b) { return a.multiply(b); }
}