Package org.apfloat.calc
Class AbstractCalculatorImpl
java.lang.Object
org.apfloat.calc.AbstractCalculatorImpl
- All Implemented Interfaces:
Serializable
,CalculatorImpl
- Direct Known Subclasses:
FunctionCalculatorImpl
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAddition.Division.Double factorial.Factorial.protected boolean
Get the formatting option.protected Long
Get the input precision.getVariable
(String name) Get a variable.Remainder.Multiplication.Negative value.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.Subtraction.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apfloat.calc.CalculatorImpl
format, function, parseDecimal, parseInteger
-
Constructor Details
-
AbstractCalculatorImpl
protected AbstractCalculatorImpl()Default constructor.
-
-
Method Details
-
negate
Description copied from interface:CalculatorImpl
Negative value.- Specified by:
negate
in interfaceCalculatorImpl
- Parameters:
x
- The argument.- Returns:
-x
- Throws:
ParseException
- In case of invalid argument.
-
add
Description copied from interface:CalculatorImpl
Addition.- Specified by:
add
in interfaceCalculatorImpl
- Parameters:
x
- First argument.y
- Second argument.- Returns:
x + y
- Throws:
ParseException
- In case of invalid arguments.
-
subtract
Description copied from interface:CalculatorImpl
Subtraction.- Specified by:
subtract
in interfaceCalculatorImpl
- Parameters:
x
- First argument.y
- Second argument.- Returns:
x - y
- Throws:
ParseException
- In case of invalid arguments.
-
multiply
Description copied from interface:CalculatorImpl
Multiplication.- Specified by:
multiply
in interfaceCalculatorImpl
- Parameters:
x
- First argument.y
- Second argument.- Returns:
x * y
- Throws:
ParseException
- In case of invalid arguments.
-
divide
Description copied from interface:CalculatorImpl
Division.- Specified by:
divide
in interfaceCalculatorImpl
- Parameters:
x
- First argument.y
- Second argument.- Returns:
x / y
- Throws:
ParseException
- In case of invalid arguments.
-
mod
Description copied from interface:CalculatorImpl
Remainder.- Specified by:
mod
in interfaceCalculatorImpl
- Parameters:
x
- First argument.y
- Second argument.- Returns:
x % y
- Throws:
ParseException
- In case of invalid arguments.
-
pow
Description copied from interface:CalculatorImpl
Power.- Specified by:
pow
in interfaceCalculatorImpl
- Parameters:
x
- First argument.y
- Second argument.- Returns:
xy
- Throws:
ParseException
- In case of invalid arguments.
-
factorial
Description copied from interface:CalculatorImpl
Factorial.- Specified by:
factorial
in interfaceCalculatorImpl
- Parameters:
x
- The argument.- Returns:
x!
- Throws:
ParseException
- In case of invalid arguments.
-
doubleFactorial
Description copied from interface:CalculatorImpl
Double factorial.- Specified by:
doubleFactorial
in interfaceCalculatorImpl
- Parameters:
x
- The argument.- Returns:
x!!
- Throws:
ParseException
- In case of invalid arguments.
-
getVariable
Description copied from interface:CalculatorImpl
Get a variable.- Specified by:
getVariable
in interfaceCalculatorImpl
- 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
Description copied from interface:CalculatorImpl
Set a variable.- Specified by:
setVariable
in interfaceCalculatorImpl
- 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 interfaceCalculatorImpl
- Parameters:
pretty
- If a fixed-point or a floating-point notation should be used.
-
setInputPrecision
Description copied from interface:CalculatorImpl
Set a fixed input precision.- Specified by:
setInputPrecision
in interfaceCalculatorImpl
- Parameters:
inputPrecision
- The precision if a fixed precision is used ornull
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
Get the input precision.- Returns:
- The input precision if a fixed precision is used or
null
for arbitrary precision.
-