public class Sum extends PostfixMathCommand
sum(1,2,3,4,5)
will be 15.
Note does not expand array in its arguments so sum([1,2],[3,4])
is [4,6]
rather than 10.
This class serves mainly as an example of a function that accepts any number of parameters. Note that the numberOfParameters is initialized to -1.
Modifier and Type | Field and Description |
---|---|
protected static Add |
addFun
Function used to add pairs of items.
|
curNumberOfParameters, name, NaN, numberOfParameters
Constructor and Description |
---|
Sum()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
checkNumberOfParameters(int n)
Must have one or more parameter
|
void |
run(java.util.Stack<java.lang.Object> stack)
Calculates the result of summing up all parameters.
|
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString
protected static Add addFun
public boolean checkNumberOfParameters(int n)
checkNumberOfParameters
in interface PostfixMathCommandI
checkNumberOfParameters
in class PostfixMathCommand
n
- number of parameters function will be called with.public void run(java.util.Stack<java.lang.Object> stack) throws EvaluationException
run
in interface PostfixMathCommandI
run
in class PostfixMathCommand
stack
- arguments for functionEvaluationException
- if function cannot be evaluatedCopyright © 2018 Singular Systems http://www.singularsys.com/jep