Package com.singularsys.jep.bigdecimal.functions

# 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`

public class BigDecAdd extends Add implements FixedPrecisionFunctionI
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:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected MathContext`
  `mc`
  Stores the math context used for calculations.
  `protected int`
  `scale`

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BigDecAdd(MathContext mc)`
  Constructor.
  `BigDecAdd(MathContext mc, int scale)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Object`
  `add(Object l, Object r)`
  Adds two numbers together.
  `Object`
  `addVec(List<?> v1, List<?> v2)`
  `Object`
  `eval(Object[] args)`
  Evaluate given an array of arguments.
  `boolean`
  `getAllowStrings()`
  Whether adding strings is allowed.
  `int`
  `getDecimalPlaces()`
  Gets the number of decimal places used.
  `MathContext`
  `getMathContext()`
  `void`
  `run(Stack<Object> stack)`
  Calls `NaryBinaryFunction.eval(Object, Object)`
  `void`
  `setAllowStrings(boolean allowStrings)`
  Sets whether strings should be allowed with this operator or not.
  `void`
  `setDecimalPlaces(int scale)`
  Sets the number of decimal places to use.
  `void`
  `setMathContext(MathContext mc)`

  ### Methods inherited from class com.singularsys.jep.functions.Add

  `add, add, add, add, eval, evaluate`

  ### Methods inherited from class com.singularsys.jep.functions.NaryBinaryFunction

  `checkNumberOfParameters, instanceOf, instanceOf, instanceOf, instanceOf`

  ### Methods 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`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### mc

    protected MathContext mc
    Stores the math context used for calculations.

  - ### scale

    protected int scale

- ## Constructor Details

  - ### BigDecAdd

    public BigDecAdd(MathContext mc)
    Constructor. Initialises the math context.
    Parameters:
      `mc` -

  - ### BigDecAdd

    public BigDecAdd(MathContext mc, int scale)

- ## Method Details

  - ### setMathContext

    public void setMathContext(MathContext mc)

  - ### getMathContext

    public MathContext getMathContext()

  - ### add

    public Object add(Object l, Object r) throws EvaluationException
    Description copied from class: `Add`
    Adds 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:
      `add` in class `Add`
    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

    public Object addVec(List<?> v1, List<?> v2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### eval

    public Object eval(Object[] args) throws EvaluationException
    Description copied from class: `NaryBinaryFunction`
    Evaluate given an array of arguments. Calls the `NaryBinaryFunction.eval(Object, Object)` method for the first pair of arguments, then repeatedly with the current result and the next argument.
    Overrides:
      `eval` in class `NaryBinaryFunction`
    Parameters:
      `args` - array of arguments to function, must have at least one element
    Returns:
      result of function
    Throws:
      `EvaluationException` - if empty array

  - ### run

    public void run(Stack<Object> stack) throws EvaluationException
    Description copied from class: `NaryBinaryFunction`
    Calls `NaryBinaryFunction.eval(Object, Object)`
    Specified by:
      `run` in interface `PostfixMathCommandI`
    Overrides:
      `run` in class `NaryBinaryFunction`
    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: `FixedPrecisionFunctionI`
    Sets the number of decimal places to use.
    Specified by:
      `setDecimalPlaces` in interface `FixedPrecisionFunctionI`
    Parameters:
      `scale` - either zero, a positive number or -1 for floating-point formats

  - ### getDecimalPlaces

    public int getDecimalPlaces()
    Description copied from interface: `FixedPrecisionFunctionI`
    Gets the number of decimal places used.
    Specified by:
      `getDecimalPlaces` in interface `FixedPrecisionFunctionI`
    Returns:
      either zero, a positive number or -1 for floating-point formats