double factorial

This commit is contained in:
Sergey Solovyev 2011-12-16 00:39:24 +04:00
parent ecb2f742b0
commit 7ee5537972
9 changed files with 11 additions and 6 deletions

View File

@ -10,7 +10,7 @@
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/eightDigitButton" a:text="8" a:id="@+id/eightDigitButton" a:text="8"
calc:textUp="ln" calc:textUp="ln"
calc:textLeft="0b:" calc:textLeft="0o:"
calc:textDown="lg" calc:textDown="lg"
calc:directionTextScale="0.5;0.5;0.5;0.33" calc:directionTextScale="0.5;0.5;0.5;0.33"
style="?digitButtonStyle" style="?digitButtonStyle"

View File

@ -10,7 +10,7 @@
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/nineDigitButton" a:text="9" a:id="@+id/nineDigitButton" a:text="9"
calc:textDown="e" calc:textDown="e"
calc:textLeft="0o:" calc:textLeft="0x:"
calc:textUp="π" calc:textUp="π"
calc:directionTextScale="0.5;0.5;0.5;0.33" calc:directionTextScale="0.5;0.5;0.5;0.33"
style="?digitButtonStyle" style="?digitButtonStyle"

View File

@ -10,7 +10,7 @@
xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator" xmlns:calc="http://schemas.android.com/apk/res/org.solovyev.android.calculator"
a:id="@+id/sevenDigitButton" a:text="7" a:id="@+id/sevenDigitButton" a:text="7"
calc:textUp="i" calc:textUp="i"
calc:textLeft="0x:" calc:textLeft="0b:"
calc:textDown="!" calc:textDown="!"
calc:directionTextScale="0.5;0.5;0.5;0.33" calc:directionTextScale="0.5;0.5;0.5;0.33"
style="?digitButtonStyle" style="?digitButtonStyle"

View File

@ -183,6 +183,7 @@
<string name="c_op_description_integral_ab">Интегрирует функцию \'f(x)\' по переменной \'x\' от \'a\' до \'b\'.</string> <string name="c_op_description_integral_ab">Интегрирует функцию \'f(x)\' по переменной \'x\' от \'a\' до \'b\'.</string>
<string name="c_pf_description_factorial">Возвращает факториал от предыдущего выражения.</string> <string name="c_pf_description_factorial">Возвращает факториал от предыдущего выражения.</string>
<string name="c_pf_description_double_factorial">Возвращает двойной факториал от предыдущего выражения.</string>
<string name="c_pf_description_percent" formatted="false">Возвращает процентное значение от предыдущего выражения.\nПримеры:\n <string name="c_pf_description_percent" formatted="false">Возвращает процентное значение от предыдущего выражения.\nПримеры:\n
100 + 50% = 150\n 100 + 50% = 150\n
100 * 50% = 50\n 100 * 50% = 50\n

View File

@ -184,6 +184,7 @@
<string name="c_op_description_integral_ab">Integrates function \'f(x)\' by \'x\' variable from \'a\' to \'b\'.</string> <string name="c_op_description_integral_ab">Integrates function \'f(x)\' by \'x\' variable from \'a\' to \'b\'.</string>
<string name="c_pf_description_factorial">Gives the factorial of the expression before.</string> <string name="c_pf_description_factorial">Gives the factorial of the expression before.</string>
<string name="c_pf_description_double_factorial">Gives the double factorial of the expression before.</string>
<string name="c_pf_description_percent" formatted="false">Gives the percent value of the expression <string name="c_pf_description_percent" formatted="false">Gives the percent value of the expression
before.\nExamples:\n before.\nExamples:\n
100 + 50% = 150\n 100 + 50% = 150\n

View File

@ -146,6 +146,7 @@ public class TextHighlighter implements TextProcessor<TextHighlighter.Result, St
if (mathType.getMathType() == MathType.text || match.length() <= 1) { if (mathType.getMathType() == MathType.text || match.length() <= 1) {
text1.append(text.charAt(i)); text1.append(text.charAt(i));
} else { } else {
text1.append(match);
i += match.length() - 1; i += match.length() - 1;
} }
} }

View File

@ -25,6 +25,7 @@ public class AndroidPostfixFunctionsRegistry extends AndroidMathRegistryImpl<Ope
static { static {
substitutes.put("%", "percent"); substitutes.put("%", "percent");
substitutes.put("!", "factorial"); substitutes.put("!", "factorial");
substitutes.put("!!", "double_factorial");
substitutes.put("°", "degree"); substitutes.put("°", "degree");
} }

View File

@ -56,6 +56,7 @@ public class TextHighlighterTest {
Assert.assertEquals("22x", textHighlighter.process("22x").toString()); Assert.assertEquals("22x", textHighlighter.process("22x").toString());
Assert.assertEquals("20t", textHighlighter.process("20t").toString()); Assert.assertEquals("20t", textHighlighter.process("20t").toString());
Assert.assertEquals("20k", textHighlighter.process("20k").toString()); Assert.assertEquals("20k", textHighlighter.process("20k").toString());
Assert.assertEquals("3!!", textHighlighter.process("3!!").toString());
Assert.assertEquals("2", textHighlighter.process("2").toString()); Assert.assertEquals("2", textHighlighter.process("2").toString());
Assert.assertEquals("21", textHighlighter.process("21").toString()); Assert.assertEquals("21", textHighlighter.process("21").toString());
Assert.assertEquals("214", textHighlighter.process("214").toString()); Assert.assertEquals("214", textHighlighter.process("214").toString());

View File

@ -113,7 +113,7 @@ public class CalculatorEngineTest {
Assert.assertEquals("2+i", cm.evaluate(JsclOperation.numeric, "2*1+√(-1)").getResult()); Assert.assertEquals("2+i", cm.evaluate(JsclOperation.numeric, "2*1+√(-1)").getResult());
try { try {
cm.getEngine().setAngleUnits(AngleUnit.rad); cm.getEngine().setAngleUnits(AngleUnit.rad);
Assert.assertEquals("0.921+3.142i", cm.evaluate(JsclOperation.numeric, "ln(5cosh(38π√(2cos(2))))").getResult()); Assert.assertEquals("0.921+πi", cm.evaluate(JsclOperation.numeric, "ln(5cosh(38π√(2cos(2))))").getResult());
Assert.assertEquals("-3.41+3.41i", cm.evaluate(JsclOperation.numeric, "(5tan(2i)+2i)/(1-i)").getResult()); Assert.assertEquals("-3.41+3.41i", cm.evaluate(JsclOperation.numeric, "(5tan(2i)+2i)/(1-i)").getResult());
} finally { } finally {
cm.getEngine().setAngleUnits(defaultAngleUnit); cm.getEngine().setAngleUnits(defaultAngleUnit);
@ -132,7 +132,7 @@ public class CalculatorEngineTest {
junit.framework.Assert.assertEquals("120", cm.evaluate(JsclOperation.numeric, "(2+2+1)!").getResult()); junit.framework.Assert.assertEquals("120", cm.evaluate(JsclOperation.numeric, "(2+2+1)!").getResult());
junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "(2.0+2.0)!").getResult()); junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "(2.0+2.0)!").getResult());
junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "4.0!").getResult()); junit.framework.Assert.assertEquals("24", cm.evaluate(JsclOperation.numeric, "4.0!").getResult());
junit.framework.Assert.assertEquals("720", cm.evaluate(JsclOperation.numeric, "3!!").getResult()); junit.framework.Assert.assertEquals("720", cm.evaluate(JsclOperation.numeric, "(3!)!").getResult());
junit.framework.Assert.assertEquals("36", Expression.valueOf("3!^2").numeric().toString()); junit.framework.Assert.assertEquals("36", Expression.valueOf("3!^2").numeric().toString());
junit.framework.Assert.assertEquals("3", Expression.valueOf("cubic(27)").numeric().toString()); junit.framework.Assert.assertEquals("3", Expression.valueOf("cubic(27)").numeric().toString());
try { try {
@ -353,7 +353,7 @@ public class CalculatorEngineTest {
Assert.assertEquals("11 259 375", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF").getResult()); Assert.assertEquals("11 259 375", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF*e").getResult()); Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF*e").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "e*0x:ABCDEF").getResult()); Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "e*0x:ABCDEF").getResult());
Assert.assertEquals("2.718", cm.evaluate(JsclOperation.numeric, "e*0x:ABCDEF/0x:ABCDEF").getResult()); Assert.assertEquals("e", cm.evaluate(JsclOperation.numeric, "e*0x:ABCDEF/0x:ABCDEF").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF").getResult()); Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF").getResult());
Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C").getResult()); Assert.assertEquals("30 606 154.462", cm.evaluate(JsclOperation.numeric, "c+0x:ABCDEF*e*0x:ABCDEF/0x:ABCDEF-c+0x:C-0x:C").getResult());
Assert.assertEquals("1 446 257 064 651.832", cm.evaluate(JsclOperation.numeric, "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) ").getResult()); Assert.assertEquals("1 446 257 064 651.832", cm.evaluate(JsclOperation.numeric, "28*28 * sin(28) - 0b:1101 + √(28) + exp ( 28) ").getResult());