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

46
java/expression/Log.java Normal file
View File

@@ -0,0 +1,46 @@
package expression;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
* @author Doschennikov Nikita (me@fymio.us)
*/
public class Log extends AbstractBinaryOperation {
public Log(AbstractExpression l, AbstractExpression r) { super(l, r); }
@Override protected String getOperator() { return "//"; }
@Override protected int getPriority() { return 3; }
@Override protected boolean isRightAssoc() { return true; }
@Override
protected int applyInt(int a, int b) {
if (a <= 0) throw new ArithmeticException("logarithm of non-positive number");
if (b <= 1) throw new ArithmeticException("logarithm base must be > 1");
int result = 0;
int power = 1;
while (power <= a / b) {
power *= b;
result++;
}
return result;
}
@Override
protected BigInteger applyBi(BigInteger a, BigInteger b) {
if (a.signum() <= 0) throw new ArithmeticException("logarithm of non-positive number");
if (b.compareTo(BigInteger.TWO) < 0) throw new ArithmeticException("logarithm base must be > 1");
int result = 0;
BigInteger power = BigInteger.ONE;
while (power.multiply(b).compareTo(a) <= 0) {
power = power.multiply(b);
result++;
}
return BigInteger.valueOf(result);
}
@Override
protected BigDecimal applyBd(BigDecimal a, BigDecimal b) {
throw new UnsupportedOperationException("log not supported for BigDecimal");
}
}