Package org.apfloat.calc
Class AbstractCalculatorImpl
- java.lang.Object
-
- org.apfloat.calc.AbstractCalculatorImpl
-
- All Implemented Interfaces:
java.io.Serializable,CalculatorImpl
- Direct Known Subclasses:
FunctionCalculatorImpl
public abstract class AbstractCalculatorImpl extends java.lang.Object implements CalculatorImpl, java.io.Serializable
Basic calculator implementation. Provides a storage for variables, and maps the elementary operators to function calls.- Version:
- 1.14.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.LonginputPrecisionprivate booleanprettyprivate static longserialVersionUIDprivate java.util.Map<java.lang.String,java.lang.Number>variables
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCalculatorImpl()Default constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Numberadd(java.lang.Number x, java.lang.Number y)Addition.java.lang.Numberdivide(java.lang.Number x, java.lang.Number y)Division.java.lang.NumberdoubleFactorial(java.lang.Number x)Double factorial.java.lang.Numberfactorial(java.lang.Number x)Factorial.protected booleangetFormat()Get the formatting option.protected java.lang.LonggetInputPrecision()Get the input precision.java.lang.NumbergetVariable(java.lang.String name)Get a variable.java.lang.Numbermod(java.lang.Number x, java.lang.Number y)Remainder.java.lang.Numbermultiply(java.lang.Number x, java.lang.Number y)Multiplication.java.lang.Numbernegate(java.lang.Number x)Negative value.java.lang.Numberpow(java.lang.Number x, java.lang.Number y)Power.voidsetFormat(boolean pretty)Set the formatting option.voidsetInputPrecision(java.lang.Long inputPrecision)Set a fixed input precision.voidsetVariable(java.lang.String name, java.lang.Number value)Set a variable.java.lang.Numbersubtract(java.lang.Number x, java.lang.Number y)Subtraction.private static java.util.List<java.lang.Number>toList(java.lang.Number x)private static java.util.List<java.lang.Number>toList(java.lang.Number x, java.lang.Number y)-
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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
variables
private java.util.Map<java.lang.String,java.lang.Number> variables
-
pretty
private boolean pretty
-
inputPrecision
private java.lang.Long inputPrecision
-
-
Method Detail
-
negate
public java.lang.Number negate(java.lang.Number x) throws ParseExceptionDescription copied from interface:CalculatorImplNegative value.- Specified by:
negatein interfaceCalculatorImpl- Parameters:
x- The argument.- Returns:
-x- Throws:
ParseException- In case of invalid argument.
-
add
public java.lang.Number add(java.lang.Number x, java.lang.Number y) throws ParseExceptionDescription copied from interface:CalculatorImplAddition.- Specified by:
addin interfaceCalculatorImpl- Parameters:
x- First argument.y- Second argument.- Returns:
x + y- Throws:
ParseException- In case of invalid arguments.
-
subtract
public java.lang.Number subtract(java.lang.Number x, java.lang.Number y) throws ParseExceptionDescription copied from interface:CalculatorImplSubtraction.- Specified by:
subtractin interfaceCalculatorImpl- Parameters:
x- First argument.y- Second argument.- Returns:
x - y- Throws:
ParseException- In case of invalid arguments.
-
multiply
public java.lang.Number multiply(java.lang.Number x, java.lang.Number y) throws ParseExceptionDescription copied from interface:CalculatorImplMultiplication.- Specified by:
multiplyin interfaceCalculatorImpl- Parameters:
x- First argument.y- Second argument.- Returns:
x * y- Throws:
ParseException- In case of invalid arguments.
-
divide
public java.lang.Number divide(java.lang.Number x, java.lang.Number y) throws ParseExceptionDescription copied from interface:CalculatorImplDivision.- Specified by:
dividein interfaceCalculatorImpl- Parameters:
x- First argument.y- Second argument.- Returns:
x / y- Throws:
ParseException- In case of invalid arguments.
-
mod
public java.lang.Number mod(java.lang.Number x, java.lang.Number y) throws ParseExceptionDescription copied from interface:CalculatorImplRemainder.- Specified by:
modin interfaceCalculatorImpl- Parameters:
x- First argument.y- Second argument.- Returns:
x % y- Throws:
ParseException- In case of invalid arguments.
-
pow
public java.lang.Number pow(java.lang.Number x, java.lang.Number y) throws ParseExceptionDescription copied from interface:CalculatorImplPower.- Specified by:
powin interfaceCalculatorImpl- Parameters:
x- First argument.y- Second argument.- Returns:
xy- Throws:
ParseException- In case of invalid arguments.
-
factorial
public java.lang.Number factorial(java.lang.Number x) throws ParseExceptionDescription copied from interface:CalculatorImplFactorial.- Specified by:
factorialin interfaceCalculatorImpl- Parameters:
x- The argument.- Returns:
x!- Throws:
ParseException- In case of invalid arguments.
-
doubleFactorial
public java.lang.Number doubleFactorial(java.lang.Number x) throws ParseExceptionDescription copied from interface:CalculatorImplDouble factorial.- Specified by:
doubleFactorialin interfaceCalculatorImpl- Parameters:
x- The argument.- Returns:
x!!- Throws:
ParseException- In case of invalid arguments.
-
getVariable
public java.lang.Number getVariable(java.lang.String name) throws ParseExceptionDescription copied from interface:CalculatorImplGet a variable.- Specified by:
getVariablein interfaceCalculatorImpl- Parameters:
name- Name of the variable.- Returns:
- Value of the variable, or
nullif the variable is not defined. - Throws:
ParseException- In case of invalid argument.
-
setVariable
public void setVariable(java.lang.String name, java.lang.Number value)Description copied from interface:CalculatorImplSet a variable.- Specified by:
setVariablein interfaceCalculatorImpl- Parameters:
name- Name of the variable.value- Value of the variable.
-
setFormat
public void setFormat(boolean pretty)
Description copied from interface:CalculatorImplSet the formatting option.- Specified by:
setFormatin interfaceCalculatorImpl- Parameters:
pretty- If a fixed-point or a floating-point notation should be used.
-
setInputPrecision
public void setInputPrecision(java.lang.Long inputPrecision)
Description copied from interface:CalculatorImplSet a fixed input precision.- Specified by:
setInputPrecisionin interfaceCalculatorImpl- Parameters:
inputPrecision- The precision if a fixed precision is used ornullfor 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 java.lang.Long getInputPrecision()
Get the input precision.- Returns:
- The input precision if a fixed precision is used or
nullfor arbitrary precision.
-
toList
private static java.util.List<java.lang.Number> toList(java.lang.Number x)
-
toList
private static java.util.List<java.lang.Number> toList(java.lang.Number x, java.lang.Number y)
-
-