# Class AbstractCalculatorImpl

java.lang.Object
org.apfloat.calc.AbstractCalculatorImpl

All Implemented Interfaces:
  `Serializable, CalculatorImpl`

Direct Known Subclasses:
  `FunctionCalculatorImpl`

public abstract class AbstractCalculatorImpl extends Object implements CalculatorImpl, Serializable
Basic calculator implementation. Provides a storage for variables, and maps the elementary operators to function calls.

Version:
  1.14.0
Author:
  Mikko Tommila
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractCalculatorImpl()`
  Default constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Number`
  `add(Number x, Number y)`
  Addition.
  `Number`
  `divide(Number x, Number y)`
  Division.
  `Number`
  `doubleFactorial(Number x)`
  Double factorial.
  `Number`
  `factorial(Number x)`
  Factorial.
  `protected boolean`
  `getFormat()`
  Get the formatting option.
  `protected Long`
  `getInputPrecision()`
  Get the input precision.
  `Number`
  `getVariable(String name)`
  Get a variable.
  `Number`
  `mod(Number x, Number y)`
  Remainder.
  `Number`
  `multiply(Number x, Number y)`
  Multiplication.
  `Number`
  `negate(Number x)`
  Negative value.
  `Number`
  `pow(Number x, Number y)`
  Power.
  `void`
  `setFormat(boolean pretty)`
  Set the formatting option.
  `void`
  `setInputPrecision(Long inputPrecision)`
  Set a fixed input precision.
  `void`
  `setVariable(String name, Number value)`
  Set a variable.
  `Number`
  `subtract(Number x, Number y)`
  Subtraction.

  ### Methods inherited from class Object

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

  ### Methods inherited from interface CalculatorImpl

  `format, function, parseDecimal, parseInteger`

- ## Constructor Details

  - ### AbstractCalculatorImpl

    protected AbstractCalculatorImpl()
    Default constructor.

- ## Method Details

  - ### negate

    public Number negate(Number x) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Negative value.
    Specified by:
      `negate` in interface `CalculatorImpl`
    Parameters:
      `x` - The argument.
    Returns:
      `-x`
    Throws:
      `ParseException` - In case of invalid argument.

  - ### add

    public Number add(Number x, Number y) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Addition.
    Specified by:
      `add` in interface `CalculatorImpl`
    Parameters:
      `x` - First argument.
      `y` - Second argument.
    Returns:
      `x + y`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### subtract

    public Number subtract(Number x, Number y) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Subtraction.
    Specified by:
      `subtract` in interface `CalculatorImpl`
    Parameters:
      `x` - First argument.
      `y` - Second argument.
    Returns:
      `x - y`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### multiply

    public Number multiply(Number x, Number y) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Multiplication.
    Specified by:
      `multiply` in interface `CalculatorImpl`
    Parameters:
      `x` - First argument.
      `y` - Second argument.
    Returns:
      `x * y`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### divide

    public Number divide(Number x, Number y) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Division.
    Specified by:
      `divide` in interface `CalculatorImpl`
    Parameters:
      `x` - First argument.
      `y` - Second argument.
    Returns:
      `x / y`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### mod

    public Number mod(Number x, Number y) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Remainder.
    Specified by:
      `mod` in interface `CalculatorImpl`
    Parameters:
      `x` - First argument.
      `y` - Second argument.
    Returns:
      `x % y`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### pow

    public Number pow(Number x, Number y) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Power.
    Specified by:
      `pow` in interface `CalculatorImpl`
    Parameters:
      `x` - First argument.
      `y` - Second argument.
    Returns:
      `xy`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### factorial

    public Number factorial(Number x) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Factorial.
    Specified by:
      `factorial` in interface `CalculatorImpl`
    Parameters:
      `x` - The argument.
    Returns:
      `x!`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### doubleFactorial

    public Number doubleFactorial(Number x) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Double factorial.
    Specified by:
      `doubleFactorial` in interface `CalculatorImpl`
    Parameters:
      `x` - The argument.
    Returns:
      `x!!`
    Throws:
      `ParseException` - In case of invalid arguments.

  - ### getVariable

    public Number getVariable(String name) throws ParseException
    Description copied from interface: `CalculatorImpl`
    Get a variable.
    Specified by:
      `getVariable` in interface `CalculatorImpl`
    Parameters:
      `name` - Name of the variable.
    Returns:
      Value of the variable, or `null` if the variable is not defined.
    Throws:
      `ParseException` - In case of invalid argument.

  - ### setVariable

    public void setVariable(String name, Number value)
    Description copied from interface: `CalculatorImpl`
    Set a variable.
    Specified by:
      `setVariable` in interface `CalculatorImpl`
    Parameters:
      `name` - Name of the variable.
      `value` - Value of the variable.

  - ### setFormat

    public void setFormat(boolean pretty)
    Description copied from interface: `CalculatorImpl`
    Set the formatting option.
    Specified by:
      `setFormat` in interface `CalculatorImpl`
    Parameters:
      `pretty` - If a fixed-point or a floating-point notation should be used.

  - ### setInputPrecision

    public void setInputPrecision(Long inputPrecision)
    Description copied from interface: `CalculatorImpl`
    Set a fixed input precision.
    Specified by:
      `setInputPrecision` in interface `CalculatorImpl`
    Parameters:
      `inputPrecision` - The precision if a fixed precision is used or `null` for arbitrary precision.

  - ### getFormat

    protected boolean getFormat()
    Get the formatting option.
    Returns:
      If a fixed-point or a floating-point notation should be used.

  - ### getInputPrecision

    protected Long getInputPrecision()
    Get the input precision.
    Returns:
      The input precision if a fixed precision is used or `null` for arbitrary precision.