factorial added

This commit is contained in:
serso
2011-10-29 16:53:09 +04:00
parent 2c08bb1b9d
commit 1995ad8b3b
7 changed files with 50 additions and 52 deletions

View File

@@ -41,8 +41,6 @@ class FromJsclNumericTextProcessor implements TextProcessor<String> {
throw new ParseException(e);
}
} else {
throw new ParseException(e);
}
}

View File

@@ -20,6 +20,7 @@ public class Functions {
}
public final static String DEGREE = "°";
public final static String FACTORIAL = "!";
public static final List<String> allPostfix = Arrays.asList(DEGREE);
public static final List<String> allPostfix = Arrays.asList(FACTORIAL, DEGREE);
}

View File

@@ -49,49 +49,8 @@ public enum MathType {
}
},
postfix_function(400, true, true, Functions.allPostfix) {
@Override
protected String getSubstituteToJscl(@NotNull String match) {
final String result;
if (match.equals(Functions.DEGREE)) {
result = PI + "/180";
} else {
result = null;
}
return result;
}
/* @Override
public int processToJscl(@NotNull StringBuilder result, int i, @NotNull String match) throws ParseException {
if (result.length() > 0) {
int startOfPrefixFunction = getPostfixFunctionStart(result, result.length() - 1);
if (result.length() > startOfPrefixFunction) {
startOfPrefixFunction = Math.max(0, startOfPrefixFunction);
final String substring = result.substring(startOfPrefixFunction);
result.setCharAt(startOfPrefixFunction, '(');
for ( int j = 0; j < substring.length(); j++ ){
if (result.length() > startOfPrefixFunction + 1 + j) {
result.setCharAt(startOfPrefixFunction + 1 + j, substring.charAt(j));
} else {
result.append(substring.charAt(j));
}
}
} else {
result.append('(');
}
super.processToJscl(result, i, match);
result.append(")");
} else {
throw new ParseException("Could not find start of prefix function!");
}
return returnI(i, match);
}*/
},
unary_operation(500, false, false, "-", "=", "!"),
postfix_function(400, false, true, Functions.allPostfix),
unary_operation(500, false, false, "-", "="),
binary_operation(600, false, false, "-", "+", "*", "×", "", "/", "^") {
@Override
protected String getSubstituteToJscl(@NotNull String match) {

View File

@@ -183,14 +183,17 @@ public enum CalculatorEngine {
final Thread thread = Thread.currentThread();
try {
//Log.d(CalculatorEngine.class.getName(), "Calculation thread started work: " + thread.getName());
//System.out.println(jsclExpression);
calculationThread.setObject(thread);
calculationResult.setObject(finalOperation.evaluate(Expression.valueOf(jsclExpression)));
} catch (ArithmeticException e) {
//System.out.println(e.getMessage());
exception.setObject(new ParseException(e.getMessage(), e));
} catch (jscl.text.ParseException e) {
//System.out.println(e.getMessage());
exception.setObject(new ParseException(e.getMessage(), e));
} catch (ParseInterruptedException e) {
System.out.print("Interrupted!");
//System.out.println(e.getMessage());
// do nothing - we ourselves interrupt the calculations
} finally {
//Log.d(CalculatorEngine.class.getName(), "Calculation thread ended work: " + thread.getName());