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

47
java/expression/Pow2.java Normal file
View File

@@ -0,0 +1,47 @@
package expression;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
/**
* @author Doschennikov Nikita (me@fymio.us)
*/
public class Pow2 extends AbstractExpression {
private final AbstractExpression operand;
public Pow2(AbstractExpression operand) {
this.operand = operand;
}
private static int pow2(int n) {
if (n < 0) throw new ArithmeticException("pow₂ of negative number: " + n);
if (n >= 31) throw new OverflowException("pow₂");
return 1 << n;
}
@Override public int evaluate(int x) { return pow2(operand.evaluate(x)); }
@Override public int evaluate(int x, int y, int z) { return pow2(operand.evaluate(x,y,z)); }
@Override public int evaluate(List<Integer> vars) { return pow2(operand.evaluate(vars)); }
@Override public BigInteger evaluateBi(List<BigInteger> vars) { throw new UnsupportedOperationException(); }
@Override public BigDecimal evaluateBd(List<BigDecimal> vars) { throw new UnsupportedOperationException(); }
@Override public String toString() { return "pow₂(" + operand + ")"; }
@Override
public String toMiniString() {
if (operand instanceof AbstractBinaryOperation) {
return "pow₂(" + operand.toMiniString() + ")";
}
return "pow₂ " + operand.toMiniString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Pow2)) return false;
return operand.equals(((Pow2) obj).operand);
}
@Override public int hashCode() { return operand.hashCode() ^ 0x504F5732; }
}