log function added + refactor of strings
This commit is contained in:
@@ -6,8 +6,11 @@
|
||||
|
||||
package org.solovyev.android.calculator.model;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import jscl.math.function.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.definitions.IBuilder;
|
||||
import org.solovyev.common.math.MathRegistry;
|
||||
@@ -113,6 +116,13 @@ public class AndroidFunctionsMathRegistry extends AbstractAndroidMathRegistry<Fu
|
||||
super(functionsRegistry, FUNCTION_DESCRIPTION_PREFIX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(@Nullable Context context, @Nullable SharedPreferences preferences) {
|
||||
super.load(context, preferences);
|
||||
|
||||
add(new CustomFunction.Builder(true, "log", new String[]{"a", "b"}, "ln(b)/ln(a)"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Map<String, String> getSubstitutes() {
|
||||
|
@@ -284,6 +284,9 @@ public enum CalculatorEngine {
|
||||
}
|
||||
|
||||
varsRegistry.load(context, preferences);
|
||||
functionsRegistry.load(context, preferences);
|
||||
operatorsRegistry.load(context, preferences);
|
||||
postfixFunctionsRegistry.load(context, preferences);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -11,6 +11,7 @@ import jscl.NumeralBase;
|
||||
import jscl.math.Expression;
|
||||
import jscl.math.Generic;
|
||||
import jscl.math.function.Constant;
|
||||
import jscl.math.function.CustomFunction;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -406,4 +407,22 @@ public class CalculatorEngineTest {
|
||||
cm.setNumeralBase(defaultNumeralBase);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLog() throws Exception {
|
||||
final CalculatorEngine cm = CalculatorEngine.instance;
|
||||
|
||||
Assert.assertEquals("∞", Expression.valueOf("1/0").numeric().toString());
|
||||
Assert.assertEquals("∞", Expression.valueOf("ln(10)/ln(1)").numeric().toString());
|
||||
|
||||
// logarithm
|
||||
Assert.assertEquals("ln(b)/ln(a)", ((CustomFunction) cm.getFunctionsRegistry().get("log")).getContent());
|
||||
Assert.assertEquals("∞", cm.evaluate(JsclOperation.numeric, "log(1, 10)").getResult());
|
||||
Assert.assertEquals("3.322", cm.evaluate(JsclOperation.numeric, "log(2, 10)").getResult());
|
||||
Assert.assertEquals("1.431", cm.evaluate(JsclOperation.numeric, "log(5, 10)").getResult());
|
||||
Assert.assertEquals("0.96", cm.evaluate(JsclOperation.numeric, "log(11, 10)").getResult());
|
||||
Assert.assertEquals("1/(bln(a))", cm.evaluate(JsclOperation.simplify, "∂(log(a, b), b)").getResult());
|
||||
Assert.assertEquals("-ln(b)/(aln(a)^2)", cm.evaluate(JsclOperation.simplify, "∂(log(a, b), a)").getResult());
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user