Package org.apfloat.calc
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.9.1
- 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.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 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
-
-
-
-
Method Detail
-
negate
public Number negate(Number x) throws ParseException
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
public Number add(Number x, Number y) throws ParseException
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
public Number subtract(Number x, Number y) throws ParseException
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
public Number multiply(Number x, Number y) throws ParseException
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
public Number divide(Number x, Number y) throws ParseException
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
public Number mod(Number x, Number y) throws ParseException
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
public Number pow(Number x, Number y) throws ParseException
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.
-
getVariable
public Number getVariable(String name) throws ParseException
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
public void setVariable(String name, Number value)
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
public void setInputPrecision(Long inputPrecision)
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
protected Long getInputPrecision()
Get the input precision.- Returns:
- The input precision if a fixed precision is used or
null
for arbitrary precision.
-
-