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

52
java/expression/Log2.java Normal file
View File

@@ -0,0 +1,52 @@
package expression;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
/**
* @author Doschennikov Nikita (me@fymio.us)
*/
public class Log2 extends AbstractExpression {
private final AbstractExpression operand;
public Log2(AbstractExpression operand) {
this.operand = operand;
}
private static int log2(int n) {
if (n <= 0) throw new ArithmeticException("log₂ of non-positive number: " + n);
int result = 0;
int v = n;
while (v > 1) {
v >>= 1;
result++;
}
return result;
}
@Override public int evaluate(int x) { return log2(operand.evaluate(x)); }
@Override public int evaluate(int x, int y, int z) { return log2(operand.evaluate(x,y,z)); }
@Override public int evaluate(List<Integer> vars) { return log2(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 "log₂(" + operand + ")"; }
@Override
public String toMiniString() {
if (operand instanceof AbstractBinaryOperation) {
return "log₂(" + operand.toMiniString() + ")";
}
return "log₂ " + operand.toMiniString();
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof Log2)) return false;
return operand.equals(((Log2) obj).operand);
}
@Override public int hashCode() { return operand.hashCode() ^ 0x4C4F4732; }
}