postfix functions
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package org.solovyev.android.calculator.math;
|
||||
|
||||
import jscl.math.Generic;
|
||||
import jscl.math.JSCLInteger;
|
||||
import jscl.math.NotIntegrableException;
|
||||
import jscl.math.Variable;
|
||||
import jscl.math.function.Function;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/26/11
|
||||
* Time: 12:58 PM
|
||||
*/
|
||||
public class Factorial extends Function {
|
||||
|
||||
public Factorial(Generic[] parameter) {
|
||||
super("fact", parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generic evaluate() {
|
||||
return expressionValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generic evalelem() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generic evalsimp() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generic evalnum() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generic antiderivative(int n) throws NotIntegrableException {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Generic derivative(int n) {
|
||||
throw new UnsupportedOperationException("Not implemented yet!");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Variable newinstance() {
|
||||
return new Factorial(null);
|
||||
}
|
||||
}
|
@@ -36,5 +36,10 @@ public interface Functions {
|
||||
String SQRT_SIGN = "√";
|
||||
String SQRT = "sqrt";
|
||||
|
||||
public static final List<String> all = Arrays.asList(SIN, SINH, ASIN, ASINH, COS, COSH, ACOS, ACOSH, TAN, TANH, ATAN, ATANH, LOG, LN, MOD, SQRT, SQRT_SIGN, EXP);
|
||||
public static final List<String> allPrefix = Arrays.asList(SIN, SINH, ASIN, ASINH, COS, COSH, ACOS, ACOSH, TAN, TANH, ATAN, ATANH, LOG, LN, MOD, SQRT, SQRT_SIGN, EXP);
|
||||
|
||||
Character FACT = '!';
|
||||
Character DEGREE = '°';
|
||||
|
||||
public static final List<Character> allPostfix = Arrays.asList(FACT, DEGREE);
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ public enum MathEntityType {
|
||||
constant,
|
||||
dot,
|
||||
function,
|
||||
postfix_function,
|
||||
unary_operation,
|
||||
binary_operation,
|
||||
group_symbols,
|
||||
@@ -26,13 +27,15 @@ public enum MathEntityType {
|
||||
|
||||
public static final List<Character> constants = Arrays.asList('e', 'π', 'i');
|
||||
|
||||
public static final List<Character> dots = Arrays.asList('.', ',');
|
||||
public static final List<Character> dots = Arrays.asList('.');
|
||||
|
||||
public static final List<Character> unaryOperations = Arrays.asList('-', '=', '!');
|
||||
|
||||
public static final List<Character> binaryOperations = Arrays.asList('-', '+', '*', '×', '∙', '/', '^' );
|
||||
|
||||
public static final List<String> functions = Functions.all;
|
||||
public static final List<String> prefixFunctions = Functions.allPrefix;
|
||||
|
||||
public static final List<Character> postfixFunctions = Functions.allPostfix;
|
||||
|
||||
public static final List<String> groupSymbols = Arrays.asList("[]", "()", "{}");
|
||||
|
||||
@@ -57,7 +60,7 @@ public enum MathEntityType {
|
||||
}
|
||||
|
||||
if ( result == null ) {
|
||||
if ( functions.contains(s) ) {
|
||||
if ( prefixFunctions.contains(s) ) {
|
||||
result = MathEntityType.function;
|
||||
} else if ( groupSymbols.contains(s) ) {
|
||||
result = MathEntityType.group_symbols;
|
||||
@@ -74,6 +77,8 @@ public enum MathEntityType {
|
||||
|
||||
if ( Character.isDigit(ch) ) {
|
||||
result = MathEntityType.digit;
|
||||
} else if ( postfixFunctions.contains(ch) ) {
|
||||
result = MathEntityType.postfix_function;
|
||||
} else if ( unaryOperations.contains(ch) ) {
|
||||
result = MathEntityType.unary_operation;
|
||||
} else if ( binaryOperations.contains(ch) ) {
|
||||
|
Reference in New Issue
Block a user