Class BigDecAdd
java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.NaryBinaryFunction
com.singularsys.jep.functions.Add
com.singularsys.jep.bigdecimal.functions.BigDecAdd
- All Implemented Interfaces:
FixedPrecisionFunctionI,PostfixMathCommandI,RealBinaryFunction,Serializable
Function class for the addition operator. It can operate on multiple
BigDecimals whose values are added or on Strings which are concatenated
together. Inheriting from NaryBinaryFunction creates an n-ary function which
is applied repeatedly if more than two arguments are provided.
Since Jep 4.1 can work with vectors.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MathContextStores the math context used for calculations.protected intFields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, description, name, NaN, numberOfParameters -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds two numbers together.Evaluate given an array of arguments.booleanWhether adding strings is allowed.intGets the number of decimal places used.voidvoidsetAllowStrings(boolean allowStrings) Sets whether strings should be allowed with this operator or not.voidsetDecimalPlaces(int scale) Sets the number of decimal places to use.voidMethods inherited from class com.singularsys.jep.functions.NaryBinaryFunction
checkNumberOfParameters, instanceOf, instanceOf, instanceOf, instanceOfMethods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString
-
Field Details
-
mc
Stores the math context used for calculations. -
scale
protected int scale
-
-
Constructor Details
-
BigDecAdd
Constructor. Initialises the math context.- Parameters:
mc-
-
BigDecAdd
-
-
Method Details
-
setMathContext
-
getMathContext
-
add
Description copied from class:AddAdds two numbers together. The parameters can be of type Number, Complex, or String. If a certain combination of types is not supported, a EvaluationException is thrown.- Overrides:
addin classAdd- Parameters:
l- The first parameter to be added.r- The second parameter to be added.- Returns:
- The sum of param1 and param2, or concatenation of the two if they are Strings.
- Throws:
EvaluationException- if the calculation cannot be performed
-
addVec
- Throws:
EvaluationException
-
eval
Description copied from class:NaryBinaryFunctionEvaluate given an array of arguments. Calls theNaryBinaryFunction.eval(Object, Object)method for the first pair of arguments, then repeatedly with the current result and the next argument.- Overrides:
evalin classNaryBinaryFunction- Parameters:
args- array of arguments to function, must have at least one element- Returns:
- result of function
- Throws:
EvaluationException- if empty array
-
run
Description copied from class:NaryBinaryFunction- Specified by:
runin interfacePostfixMathCommandI- Overrides:
runin classNaryBinaryFunction- Parameters:
stack- arguments for function- Throws:
EvaluationException- if function cannot be evaluated
-
getAllowStrings
public boolean getAllowStrings()Whether adding strings is allowed. (Treated as concatenation ).- Returns:
- true if allowed
- Since:
- 3.4.0
-
setAllowStrings
public void setAllowStrings(boolean allowStrings) Sets whether strings should be allowed with this operator or not.- Parameters:
allowStrings- When true, strings are allowed. When false an IllegalParameterException is thrown during evaluation.- Since:
- 3.4.0
-
setDecimalPlaces
public void setDecimalPlaces(int scale) Description copied from interface:FixedPrecisionFunctionISets the number of decimal places to use.- Specified by:
setDecimalPlacesin interfaceFixedPrecisionFunctionI- Parameters:
scale- either zero, a positive number or -1 for floating-point formats
-
getDecimalPlaces
public int getDecimalPlaces()Description copied from interface:FixedPrecisionFunctionIGets the number of decimal places used.- Specified by:
getDecimalPlacesin interfaceFixedPrecisionFunctionI- Returns:
- either zero, a positive number or -1 for floating-point formats
-